我知道很多人问这个问题,但所有答案都是特定的应用程序,所以我不明白如何为我的应用程序工作。
tableData = [NSArray arrayWithObjects:@"Chocolate Brownie", @"Mushroom Risotto", nil];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section
{
return [tableData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;`
}
原因是uttableData
变量不被保留,并且您已经通过工厂方法分配了它,并且已经自动释放了。
在 .h 文件中,使其保留属性并与 self 一起使用此变量。在你的代码中。
@property(nonatomic,retain) NSArray *tableData;
in .m,
@synthesize tableData;
然后像这样使用它:
self.tableData = [NSArray arrayWithObjects:@"Chocolate Brownie", @"Mushroom Risotto", nil];
现在您不会收到任何错误,因为表数据未保留。
不要忘记释放它dealloc
如果您没有使用 ARC。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)