Раздел UITableView, когда предыдущий раздел находится вне экрана iPhone - PullRequest
0 голосов
/ 09 февраля 2012

Я занимаюсь разработкой приложения для iPhone, и у меня возникли проблемы с проверкой раздела сгруппированного табличного представления.Когда первый раздел больше не отображается из-за того, что я прокрутил табличное представление вниз, а табличное представление отскочило назад, второй раздел получит настройки из первого раздела?Я проверяю, какой раздел это со значением indexPath.section.Как я могу решить это?Извините, если мой английский неверен!

Извините за отсутствующий код!Вот фрагмент кода cellForRowAtIndexPath:

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

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault           reuseIdentifier:CellIdentifier];
    }
    if(indexPath.section == 0){
        pinSwitch.hidden = YES;
    cell.imageView.image = [UIImage imageNamed:@"test_item.png"];
    if([headarray count] != 0){
        if(indexPath.row > [headarray count] - 1){
            cell.imageView.alpha = 0;
            cell.textLabel.text = [NSString stringWithFormat:@"Add new",indexPath.row + 1];

        }
        else{
            cell.imageView.alpha = 1;
            NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
            cell.textLabel.text = [infoarray objectAtIndex:0];
        }
    }
}
    else if(indexPath.section == 1){


    if(indexPath.row == 0){
//some more cell data
}

Я думаю, этого должно быть достаточно, чтобы показать мою проблему!

1 Ответ

0 голосов
/ 09 февраля 2012

вставьте код для генерации ячейки, кажется, вы неправильно используете механизм повторного использования ячейки

EDIT: код не полный, я думаю, вы должны сделать что-то вроде этого:

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

static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault           reuseIdentifier:CellIdentifier];
    }
    if(indexPath.section == 0){
        pinSwitch.hidden = YES;
    cell.imageView.image = [UIImage imageNamed:@"test_item.png"];
    if([headarray count] != 0){
        if(indexPath.row > [headarray count] - 1){
            cell.imageView.alpha = 0;
            cell.textLabel.text = [NSString stringWithFormat:@"Add new",indexPath.row + 1];

        }
        else{
            cell.imageView.alpha = 1;
            NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
            cell.textLabel.text = [infoarray objectAtIndex:0];
        }
    }
}
    else if(indexPath.section == 1){
        if(indexPath.row == 0){
  // you should fill cell data for all cases !!!!  
  }
} else { // for example
            cell.imageView.alpha = 1;
            NSArray *infoarray = [headarray objectAtIndex:indexPath.row];
            cell.textLabel.text = [infoarray objectAtIndex:0];
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...