我的项目中没有xib文件或故事板.在这种情况下,如何设置单元标识符?以下是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"test");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [self.entries objectAtIndex:indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
尝试用此替换您的代码(使用ARC):
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.text = [self.entries objectAtIndex:indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
++
| 归档时间: |
|
| 查看次数: |
760 次 |
| 最近记录: |