2012-03-28 61 views
0

我的問題是我無法顯示具有靜態單元的UITableViewController的繼承類。我在UITableViewController中使用Storyboard進行簡單的自定義單元格設置(我想獲得設置應用程序的行爲)。但我需要將它嵌套在顯示自定義頂部欄的另一個UIViewController中(如導航欄面板)。所以,當我打開我的UITableViewController這種結構:繼承UITableViewController的正確方法?

#import <UIKit/UIKit.h> 

@interface MyCoolTableVC : UITableViewController 

@end 

我沒有得到任何的問題,這是我在故事板製造商設置的所有定製單元都顯示在分組表視圖有道。但是,當我使用的子類的UITableViewController:

#import <UIKit/UIKit.h> 
#import "MyCoolTableVCSubclass.h" 
@interface MyCoolTableVC : MyCoolTableVCSubclass 

@end 

我得到這樣的結果:

enter image description here

它顯示的tableView的野生外觀,無節和自定義單元格。 我打開我的控制器使用此代碼,如果它可以幫助:

UIViewController *vcToGo = nil; 
UIStoryboard *storyBoard = [[UIStoryboard storyboardWithName:@"MyCoolStoryboard" bundle:nil] init]; 
vcToGo = [storyBoard instantiateViewControllerWithIdentifier:@"profileTable"]; 
[self.navigationController pushViewController:vcToGo animated:YES]; 

回答

2

使用靜態細胞,表視圖的數據源必須被設置爲UITableViewController子類,你不得自己實現數據源的方法

基本的UITableViewController在它自己的實現cellForRowAtIndexPath等中提供了表格視圖的所有內容,使用了你放入故事板的內容。所以如果你的數據源不能從UITableViewController繼承,它將無法填充表。

(注 - 這是我認爲是基於我自己的實驗發生了什麼,UITableViewController中的內部都沒有提供給我)

+0

謝謝你,問題是,我已經超重寫數據源的方法。 – kokoko 2012-03-28 15:43:03