这可能是一个愚蠢的问题,但我是 iPhone 开发的新手,无论如何我有一个 NSMutableArray
,其中包含从服务器加载的信息。我想把这些信息放在一张 table 上。我四处寻找有关如何执行此操作的一些想法,然后遇到了很多人似乎都在使用此代码来执行此操作:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"] autorelease];
}
cell.textLabel.text = [myArray objectAtIndex:[indexPath row]];
NSLog(@"Cell is %@", [myArray objectAtIndex:indexPath.row]);
return cell;
现在我的问题在 if 语句中,它给了我两个错误,自动释放说:在引用计数模式下不可用且不可用,并且 arc 禁止自动释放消息发送,有什么想法吗?谢谢你的帮助
最佳答案
您拥有的代码是较旧的代码,只能按原样使用手动引用计数 (MRC)。较新的项目默认使用自动引用计数 (ARC)。只需删除对 autorelease
的调用即可。
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
关于ios - NSMutableArray 到 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15513384/