UITableView - назначение массивов правым разделам в UITableView - PullRequest
0 голосов
/ 01 февраля 2012

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

- (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 Ответ

1 голос
/ 01 февраля 2012

Сделайте метод подобным этому

- (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];
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...