SecondiosAppTutorial--學習筆記,學習筆記app

來源:互聯網
上載者:User

SecondiosAppTutorial--學習筆記,學習筆記app

自學SecondiosAppTutorial過半,運行程式報錯了,最終問題找到,英文文檔讀起來很有挫敗感,但耐心就能發現問題,Xcode的問題提示很明確清楚。如下:

/*Debug 輸出的報錯資訊,顯示TableView cell為空白值*/*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

 tableView 沒有傳回值,cell 值為null。設計TableView的實現方法在MasterViewController.m中,先從代碼著手找問題。

 1  1 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 2  2     /*UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 3  3  4  4     NSDate *object = self.objects[indexPath.row]; 5  5     cell.textLabel.text = [object description]; 6  6     return cell;*/ 7  7     static NSString *CellIdentifier = @"BirdSightingCell";/*BirdSightingCell是表格中cell的Identifier屬性名稱字*/ 8  8      9  9     static NSDateFormatter *formatter = nil;10 10     if (formatter == nil) {11 11         formatter = [[NSDateFormatter alloc] init];12 12         [formatter setDateStyle:NSDateFormatterMediumStyle];13 13     }14 14     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];15 15       NSLog(@"111222%@",cell);16 16     BirdSighting *sightingAtIndex = [self.dataController objectInListAtIndex:indexPath.row];17 17     [[cell textLabel] setText:sightingAtIndex.name];18 18     [[cell detailTextLabel] setText:[formatter stringFromDate:(NSDate *)sightingAtIndex.date]];19 19     NSLog(@"111222%@",cell);20 20     return cell;21 21 }

cell沒有值,依次輸出資訊15、19輸出內容都是null。那麼第7行就很可能出錯了。BirdSightingCell是 TableView中cell的Identifier的屬性值,發現自己的表格中的值竟然是cell。恍然大悟。具體位置如下:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.