- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"RecipeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
return cell;
}
-----------------------
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell.textLabel.text = [dataArray objectAtIndex:indexPath.row];
return cell;
}
ios tableview
------解决方案--------------------
可以参考下这里的Creating Strings说明:https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/Strings/Articles/CreatingStrings.html
字符串常量的话,在编译程序时就已经确定好了字符空间大小,程序加载时就会分配好对应的地址,程序关闭时才会释放,整个程序运行过程中不用去释放。
而alloc出来的NSString则是动态分配与释放。
------解决方案--------------------
非ARC的情况多吧,一方面方便兼容低版本的IOS系统版本,另一方面也好自己控制内存,查内存泄露什么的。