2010-09-08 38 views
1

我的熱切夢想是以編程方式確定具有不同行大小的UITableView。我已閱讀UITableViewDataSource文檔,我實現這些方法:爲什麼rowHeight數據源方法不被稱爲

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; 
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section; 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; 

裏面,我們可以在這裏看到:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return (CGFloat) 200.0f; 
} 

- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section 
{ 
    return 1; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell* test = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil ]; 

    test.textLabel.text = @"TEST"; 

    CGRect ffframe = test.frame; 

    ffframe.size.height *= 200.0f; 

    test.frame = ffframe; 

    return test;   
} 

這些只是試圖做一個簡單的表格,有一個排,和身高200.0。我嘗試在委託方法中返回高度,並明確設置它。兩者都不起作用。

我嘗試在調試器中捕獲heightForRow方法,它似乎永遠不會被調用。

我的表格行總是我在界面生成器中設置的大小。

我的數據源連接正確,否則它不會得到行和textLabel權利。

+0

heightForRowAtIndexPath是一個委託方法,而不是數據源 - 您是否將對象設置爲表的委託? – Vladimir 2010-09-08 09:08:51

回答

6

這是一個委託方法,以便確保您在viewDidLoad中有

self.tableview.delegate = self; 

否則有鏈接到控制器中的廈門國際銀行的實現代碼如下委託財產。

+2

是的,這是解決方案。爲什麼它是一個委託方法而不是數據源方法似乎很奇怪。但只要我設置它的委託它的作品。 – 2010-09-08 09:40:42

2

小心,這種方法是一個tableview delegate而不是dataSource方法。