2013-07-16 48 views
0

在我目前的應用程序中,我有24個不同的視圖,每個視圖都有它自己的ViewController。隨着時間的流逝,我已經認識到,將它們改爲TableViewController不僅會更好地發揮作用,而且事實上它會更好看。如何將自定義類添加到我的UITableViewController?

通常情況下,我一直在爲我的視圖分配自定義類的方式是在Xcode中進入:File> New> File> Objective-C Class。

我做了這個類,並確保它是UIViewController的一個子類。文件創建完成後,我單擊故事板文件中的View Controller,轉到檢查器並將自定義類設置爲myNewViewController,全部完成!

但是,在使用UITableView時,情況並非如此,我可以在故事板文件中添加表格視圖,自定義/添加節/單元格等,但是當我想要分配新類時我創建遵守上述步驟,但這次我從UITableViewController

我得到以下警告子類: enter image description here

有了這個是不完整的代碼:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
#warning Potentially incomplete method implementation. 
    // Return the number of sections. 
    return 0; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
#warning Incomplete method implementation. 
    // Return the number of rows in the section. 
    return 0; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; 

    // Configure the cell... 

    return cell; 
} 

此外,視圖在iOS設備上運行時顯示爲空白。

我知道這個實現必須在它可以正確運行之前完成,但是有沒有一個特定的方法可以將我正在使用的視圖和它的ViewController鏈接起來?這種方式都不需要這種配置?

我的下一步要遵循什麼?

感謝您的&意見!

編輯我也試圖設置小區標識爲「細胞」,並試圖改變值,以便numberOfSections返回5,和numberOfRowsInSection返回2,但仍然沒有運氣,應用程序崩潰,我得到這個在調試日誌:

*** 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' 
*** 

回答

1

您正在使用靜態單元。您不應該使用數據源方法。

+0

我編輯了問題中的代碼,您提到的方法已經實現。 @Abdullah Shafique – vzm

+0

是的,但在這種方法中,你應該確定這些單元包含的內容。 –

+0

您是否在故事板中設置了單元格標識符? –

相關問題