use*_*809 2 iphone xcode uitableview
我知道很多人问这个,但所有答案都是特定的应用程序,所以我不明白如何为我的应用程序工作.
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;`
}
Run Code Online (Sandbox Code Playgroud)
因为ut tableData变量的原因没有保留,你已经通过工厂方法分配了它已经自动释放.
在.h文件中,使其保留属性并将此变量与self一起使用.在你的代码中.
@property(nonatomic,retain) NSArray *tableData;
Run Code Online (Sandbox Code Playgroud)
在.m,
@synthesize tableData;
Run Code Online (Sandbox Code Playgroud)
然后使用它像:
self.tableData = [NSArray arrayWithObjects:@"Chocolate Brownie", @"Mushroom Risotto", nil];
Run Code Online (Sandbox Code Playgroud)
现在你不会得到任何错误,因为现在保留了tableData.
dealloc如果您不使用ARC,请不要忘记将其释放.
| 归档时间: |
|
| 查看次数: |
39288 次 |
| 最近记录: |