默认UITableview提供错误或单元格返回null

Mor*_*ang 3 objective-c uitableview ios

我正在设计一个自定义原型单元格,里面有很多标签,文本字段和按钮.

我在故事板上用原型单元创建了一个tableview控制器.我添加了一个objective-c tableviewcontroller类.并连接他们.Xcode添加的默认代码本身就是错误.

in.h中

@interface CreaatePlistTableViewController : UITableViewController<UITableViewDelegate, UITableViewDataSource>
Run Code Online (Sandbox Code Playgroud)

in.m

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

        // Configure the cell...

        return cell;
    }
Run Code Online (Sandbox Code Playgroud)

错误:

** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
Run Code Online (Sandbox Code Playgroud)

我已将代码更改为此编译但返回一个空单元格.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    // NOTE: Add some code like this to create a new cell if there are none to reuse
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

    }
    // Configure the cell...
    UILabel *labelMeetingDate = (UILabel *)[cell viewWithTag:11];
    labelMeetingDate.text = @"Meeting Date";

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

部分和行设置为1 btw.

如何将标签和文本字段添加到原型单元格,或者为什么它会给出错误或返回null?

Mic*_*han 6

你需要设置cellIdentifier单元格本身storyboard.第四个标签结束.在Table View Cell属性下列出Identifier