cellForRowAtIndexPath игнорирует разделы - PullRequest
0 голосов
/ 22 октября 2018

в моем UITableViewController я определил 3 раздела.Но если я хочу получить доступ к большему количеству разделов в методе cellForRowAtIndexPath, чем в первом, это игнорируется.Например, если я хочу добавить строку во втором разделе.У кого-нибудь есть решение проблемы?

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

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

if (indexPath.section == 0) {
    if (indexPath.row == 0) {
        ..
        return cell;
    }
    if (indexPath.row == 1) {
        ..
        return cell;
    }
    if (indexPath.row == 2) {
        ..
        return cell;
    }
}
if (indexPath.section == 1) {
            UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:aufgabe];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:aufgabe];
    }
    [cell.textLabel setText:@"Test"];
    }
}
else if (indexPath.section == 2) {
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:geraet];
    return cell;
}
   return nil;
}

1 Ответ

0 голосов
/ 22 октября 2018

Забавно!Я исправил это для себя.Мне пришлось заполнить метод numberOfRowsInSection.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   if (section == 0) {
       return 3;
   }
   if (section == 1) {
       return 5;
   }
   else {
       return 0;
   }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...