iOS:单元格未在TableView中注册

iOS:单元格未在TableView中注册,ios,Ios,我遵循这一点,并坚持与入门部分本身。在本文中,单元格是通过编程进行注册的。我按照所有步骤下载了代码,并将其与我的代码进行了比较,但无法找出问题所在 shcappedelegate.m - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

我遵循这一点,并坚持与入门部分本身。在本文中,单元格是通过编程进行注册的。我按照所有步骤下载了代码,并将其与我的代码进行了比较,但无法找出问题所在
shcappedelegate.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        _toDoItems = [[NSMutableArray alloc] init];
        [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Feed the cat"]];
        [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Buy eggs"]];
        [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Pack bags for WWDC"]];

      }
}
- (void)viewDidLoad:(BOOL)animated
{
    [super viewDidLoad];
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _toDoItems.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *ident = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];
    int index = [indexPath row];
    SHCToDoItem *item = _toDoItems[index];
    NSLog(@"%@",item.text);
    cell.textLabel.text = item.text;

    return cell;
}
@实现代理

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[SHCViewController alloc] initWithNibName:@"SHCViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
SHCViewController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        _toDoItems = [[NSMutableArray alloc] init];
        [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Feed the cat"]];
        [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Buy eggs"]];
        [_toDoItems addObject:[SHCToDoItem toDoItemWithText:@"Pack bags for WWDC"]];

      }
}
- (void)viewDidLoad:(BOOL)animated
{
    [super viewDidLoad];
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
}

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _toDoItems.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *ident = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ident forIndexPath:indexPath];
    int index = [indexPath row];
    SHCToDoItem *item = _toDoItems[index];
    NSLog(@"%@",item.text);
    cell.textLabel.text = item.text;

    return cell;
}

此处NSLog IN
tableView:(UITableView*)tableView cellForRowAtIndexPath:
未在控制台上打印。

设置数据源后,将重新加载表方法调用为
[self.tableview重载数据]

试试这个

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.dataSource = self;
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.tableview reloadData];
}

谢谢我有这个问题。它是带有viewDidLoad:(BOOL)动画的。当我刚刚使用-(id)viewDidLoad时,它工作得很好。但我不知道为什么?@Navjot这是调用该方法的正确方法,请注意,这是默认viewcontroller委托机制中的amethod-