我是Iphone开发的新手.如果我问一些非常简单的问题,请耐心等待.
在我的应用程序中,我有多个视图(即.xib文件).上点击主视图中的按钮(CouponWebsiteViewController.Xib)应用程序应该加载含有UITable所述第二视图(BrowseList.Xib),我有来填充UITable与一些数据.我编写了以下代码来填充BrowseList.m文件中的数据:
- (void) viewDidLoad{
arrayData = [[NSArray alloc] init];
arrayData = [arrayData arrayByAddingObject:@"dfsgdf"];
arrayData = [arrayData arrayByAddingObject:@"aaaaaa"];
self.lblNewScreen.text = [arrayData objectAtIndex:0];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [arrayData count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier]
autorelease];
}
NSString *cellValue = [arrayData objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
[tableView setEditing:YES animated:YES];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
但它不是在填充表中的数据,当我调试代码,我发现它不执行的cellForRowAtIndexPath方法,但它正在调试numberOfRowsInSection和numberOfSectionsInTableView方法.
但有趣的是,当我在CouponWebsiteViewController.m上编写相同的代码(即在主视图上)时,它会填充表中的数据.
关键是这个代码在主视图上工作正常,但它不适用于其他视图.
任何人都可以告诉我我缺少什么或任何其他方式在主视图以外的视图上填充UITable.
提前致谢.拉夫
我不是积极的,但这里有一些想法.
viewDidLoad为时已晚. ViewDidLoad在数据已经放入表格后执行.尝试将此代码放在initWithStyle方法或init您拥有的任何方法中.或者你甚至可以把它放在ViewWillAppear方法中,但是请确保遵循下一个建议.[self.tableView reloadData]在viewDidLoad方法结束时调用.虽然这不像第一个建议那么理想.您确定将类设置为表中的dataSource吗?要执行此操作,请在Interface Builder中按住Ctrl键并单击表视图,然后将其拖到占位符下的文件所有者.然后选择dataSource(也可以委托,具体取决于您的控制器视图设置).
| 归档时间: |
|
| 查看次数: |
23266 次 |
| 最近记录: |