没有cellidentifier ios的cellForRowIndexPath

Has*_*eer 0 uitableview ios

我的项目中没有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)

Jor*_*tel 5

尝试用此替换您的代码(使用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)

++