我知道很多人问这个问题,但所有答案都是特定的应用程序,所以我不明白如何为我的应用程序工作。
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;`
}
最佳答案
原因是 ut tableData
变量没有被保留,并且您已经通过工厂方法分配了它,并且已经自动释放了。
在.h文件中,使其保留属性并与self一起使用该变量。在你的代码中。
@property(nonatomic,retain) NSArray *tableData;
以 .m 为单位,
@synthesize tableData;
然后像这样使用它:
self.tableData = [NSArray arrayWithObjects:@"Chocolate Brownie", @"Mushroom Risotto", nil];
现在您不会收到任何错误,因为现在保留了 tableData。
如果您不使用 ARC,请不要忘记在 dealloc
中释放它。
关于iphone - Xcode "Use of undeclared identifier",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11175938/