ios - NSMutableArray 到 UITableView

标签 ios objective-c uitableview

这可能是一个愚蠢的问题,但我是 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/

相关文章:

ios - 在 UISearchbar 和 UITextfields 下面添加一个下拉建议

iphone - UITableView 不显示解析的数据

ios - swift中的函数数组(输出需要说明)

ios - 我想将 Apple Pay 集成到我的应用程序中。 Apple 是否负责收款方面的事宜?

ios - 一个 UITableView 嵌入了一个 UIScrollView,滑动删除是行不通的

javascript - 在 ios safari 和 chrome 中使用客户端 javascript 设置安全 cookie

ios - 如何在 Apple-Watch 上获取 iPhone 日历事件提醒

ios - 捕捉固定步数的 UISlider(如 iOS 7 设置应用程序中的文本大小)

ios - 估计数据和服务器数据不匹配 Parse.com

ios - 添加解析对象后发出重新加载 TableView 的问题