我有 ios 应用程序,其中包含 7 个具有不同数据的表视图。我从 plist 文件中填充每个表格,我需要有页面控制,并且在每个页面中我需要一个表格视图。我放了页面控件,放在第一页的表格没有改变,我在其他页面中看到了它。如何确定每页的页数和内容?我把这个
- (void)viewDidLoad
{
[super viewDidLoad];
int page=pageControl.currentPage;
//pageControlList=[[NSArray alloc]initWithObjects:tabelView,tabelViewq, nil];
pageControlBeingUsed = NO;
self.scrollView.contentSize = CGSizeMake(960, 424);
self.tabelView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
NSError *err;
for (page=0; page<7; page++) {
switch ([pageControl currentPage]) {
case 0:{
NSFileManager *fileManager = [NSFileManager defaultManager];
//getting the path to document directory for the file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"%@",paths);
NSString *documentDir = [paths objectAtIndex:0];
NSString *path = [documentDir stringByAppendingPathComponent:@"News.plist"];
//checking to see of the file already exist
if(![fileManager fileExistsAtPath:path])
{
//if doesnt exist get the the file path from bindle
NSString *correctPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"News.plist"];
NSLog(@"plist exist");
//copy the file from bundle to document dir
[fileManager copyItemAtPath:correctPath toPath:path error:&err];
}
// read data from plist file
presedients=[[NSMutableDictionary alloc]initWithContentsOfFile:path ];
Names=[presedients objectForKey:@"Name"];
url=[presedients objectForKey:@"URL"];
NSLog(@"%@",presedients);
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
}
break;
case 1:{
pageControl.currentPage =pageControl.currentPage+1;
NSFileManager *fileManager = [NSFileManager defaultManager];
//getting the path to document directory for the file
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"%@",paths);
NSString *documentDir = [paths objectAtIndex:0];
NSString *pathq = [documentDir stringByAppendingPathComponent:@"Quran.plist"];
//checking to see of the file already exist
if(![fileManager fileExistsAtPath:pathq])
{
//if doesnt exist get the the file path from bindle
NSString *correctPathq = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Quran.plist"];
NSLog(@"plist exist");
//copy the file from bundle to document dir
[fileManager copyItemAtPath:correctPathq toPath:pathq error:&err];
}
// read data from plist file
presedientsq=[[NSMutableDictionary alloc]initWithContentsOfFile:pathq ];
NamesQ=[presedientsq objectForKey:@"Name"];
urlq=[presedientsq objectForKey:@"URL"];
NSLog(@"%@",presedientsq);
}
break;
但程序见案例一(我把第一个表放在所有页面中)。为什么?难道我的条件不对?
问候