2012-01-31 4 views
0

У меня есть UITableView, что у меня есть настройка с двумя разделами. В приведенном ниже коде показан один и тот же текст ячейки по всему UITableView. Мой вопрос вкратце: как вы назначаете разделы NSArrays?UITableView - назначение массивов в правые секции в UITableView

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

    UITableViewCell *cell = [toStartPicker dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 
    } 
    cell.textLabel.text= [nameJan objectAtIndex:indexPath.row]; 
    cell.detailTextLabel.text= [subTitlesJan objectAtIndex:indexPath.row]; 

    UITableViewCell *cellTwo = [toStartPicker dequeueReusableCellWithIdentifier:@"cellTwo"]; 
    if (cellTwo == nil) { 
     cellTwo = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellTwo"]; 
    } 
    cellTwo.textLabel.text= [nameFeb objectAtIndex:indexPath.row]; 
    cellTwo.detailTextLabel.text= [subTitlesFeb objectAtIndex:indexPath.row]; 

    return cell; 
} 

ответ

1

Сделать метод как этот

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

    UITableViewCell *cell = [toStartPicker dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"]; 
    } 
    if(indexPath.section == 0) 
    { 
     cell.textLabel.text= [nameJan objectAtIndex:indexPath.row]; 
     cell.detailTextLabel.text= [subTitlesJan objectAtIndex:indexPath.row]; 
    } 
    else 
    { 
     cell.textLabel.text= [nameFeb objectAtIndex:indexPath.row]; 
     cell.detailTextLabel.text= [subTitlesFeb objectAtIndex:indexPath.row]; 
    } 
    return cell; 
} 

Кроме того, убедитесь, что следующие методы выглядеть

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    if(0 == section) 
    { 
     return [nameJan count]; 
    } 
    else 
    { 
     return [nameFeb count]; 
    } 
} 
+0

Спасибо большое за ответ! – Seb