2011-11-25 12 views
1

我已經得到以下代碼。該陣列由XML建立起來的,所以每個節點都有一個標題(這將是該部分的標題)和文本iPhone:陣列中的表格行/區段 - 設置陣列中的區段和行數據量

因此,每個節點都有1個單元和1題(將在細胞本身去)

- (NSInteger) 
    numberOfSectionsInTableView:(UITableView *)tableView { 
    return [arrySummaryTitle count]; 
} 


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


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

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    AssessObject *newObj1 = [[AssessObject alloc] init]; 
    newObj1=[totalArray objectAtIndex:indexPath.row]; 

    cell.textLabel.text = newObj1.routeImage; 

    cell.textLabel.lineBreakMode = UILineBreakModeWordWrap; 
    cell.textLabel.numberOfLines = 0; 
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0]; 


    return cell; 
} 

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ 
    return [arrySummaryTitle objectAtIndex:section]; 
} 

我真的很努力地做的是循環通過單元格和節標題循環通過newObj1.routeImage並有一個數組中的單元格文本和單元格部分?我甚至在努力解釋哈哈

陣列被建立起來,如:

章節標題,章節標題,章節標題等

同樣的文本,他們都在newObj1是.whatever

所以我需要它,這樣的表建立這樣的:

[Section Header] 
[Section Text] 

[Section Header] 
[Section Text] 

有道理?湯姆

+0

警告:您正在泄漏內存。 'AssessObject * newObj1 = [[AssessObject alloc] init]'之後';' ,你應該在指向一個新的值之前調用[newObj1 release]。你也可以在零發起'newObj1'... – Vinzzz

回答

3
newObj1 = [totalArray objectAtIndex:indexPath.section]; 

這將讓部分,而不是行的,因爲在每一個部分和indexPath.row只有一個項目總是會返回相同的值。請參閱NSIndexPath UIKit Additions

+0

謝謝你。改變它的時候它是否應該起作用?因爲它在我的表格中仍然只顯示一個結果 – TMB87