2012-04-18 117 views
1

我現在用的UITableView工作,我的有什麼表視圖不顯示數據,iphone

MyClass.h

@interface MyClass的:的UIViewController {

}

@property(strong,strong)UILabel * name;

@property(strong,strong)UILabel * add;

MyClass.m

- (NSInteger的)的tableView:(UITableView的*)atableView numberOfRowsInSection:(NSInteger的)部分{

return 3 ; 
} 

- (的UITableViewCell *) tableView :(UITableView *)aTableView cellForRowAtIndexPath :(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"cell"; 
tableCell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
................................................... 

return tableCell; 

}

當我把我在numberOfRowsInSection破發點,似乎是根本沒有被執行的時候。 現在令我困惑。 如果您以前遇到過,請諮詢。

感謝

+0

請在發佈前修改你的代碼。你的''@ property''在錯誤的地方。你用點省略的代碼對於顯示內容起着重要作用。 – 2012-04-18 00:39:22

+0

我剛剛編輯...第一件事,我只是想確保numberOfRowsInSection正在執行或不。否則,顯示是沒有什麼.... – tranvutuan 2012-04-18 00:49:05

回答

3

這樣做的最常見原因是沒有設置你的視圖控制器的表視圖的委託和數據源。如果它是在故事板中構建的,則可以通過選擇表格上的連接檢查器並將這些屬性拖到視圖控制器來完成此操作。

否則,將其設置在這樣的代碼:

self.tableView.delegate = self; 
self.tableView.datasource = self; 
+0

感謝提醒我。我剛剛回頭看storyBoard,並意識到我沒有將dataSource和委託設置到tableView。 – tranvutuan 2012-04-18 00:52:15