2010-06-23 61 views
1

道歉,如果這是一個簡單的問題,但谷歌搜索無法幫助我。 我打算在表視圖中顯示3個數據數組,每個數組在表視圖的不同部分。iPhone UITableView與多個部分

任何人都可以提供一個鏈接到一個很好的教程或示例代碼,可以幫助我呢?

再次表示歉意,如果這是一個簡單的問題和答案,但我是Xcode的新手,併爲我的第一個嚴肅的項目工作。

謝謝!

回答

8

在你TableViewController實現:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 3; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
return [[self getDataArray:section]count];//implement getDataArray 
} 

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

    static NSString *CellIdentifier = @"Cell"; 

    NSObject *data = [[self getDataArray:indexPath.section]objectAt:indexPath.row];//implement getDataArray 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     //add Code to populate cell with data 
    } 
    return cell; 
} 

其他方法可能實現:

- (UIView *)tableView: (UITableView *)tableView viewForHeaderInSection: (NSInteger)section 
- (CGFloat)tableView:(UITableView *)aTableView heightForHeaderInSection:(NSInteger)section 
+0

非常感謝,我並沒有意識到這是因爲這容易。無論如何,我已經完成了大部分代碼,我只需要完成它!再次感謝您花時間回答。 – 2010-06-23 18:12:14

+0

爲什麼這麼難在網上找到?我一直在尋找這幾天。 – bdares 2011-06-16 01:56:44

相關問題