Мое приложение iphone падает, когда я использую табличное представление - PullRequest
0 голосов
/ 15 января 2012
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *theCell=[UITableViewCell alloc];
     theCell=[theCell initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];

      NSLog(@"%i",[table count]);

         theCell.textLabel.text=[table objectAtIndex:[indexPath row]];  

    return theCell;
}

В файл Values.plist вставлено три значения, и они заполняют "таблицу" NSArray в функции viewDidLoad (), но мое приложение падает на

" theCell.textLabel.text=[table objectAtIndex:[indexPath row]];  "
But the line "NSLog(@"%i",[table count]);" works and shows me 3
please help .

Ответы [ 2 ]

1 голос
/ 15 января 2012

Это стандартная реализация:

 - (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];
        }


       cell.textLabel.text = [table objectAtIndex:indexPath.row];
        return cell;
    }

В качестве дополнительного примечания это реализация ARC.Если вы не используете ARC, просто добавьте autoRelease:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]autoRelease];

и убедитесь, что ваш dataSource numberOfSections установлен правильно:

return 1;

и numberOfRows установлено в массив:

return [table count];
0 голосов
/ 15 января 2012

Пожалуйста, позаботьтесь о следующих проблемах:

1) Убедитесь, что NSArray имеет значения, то есть он заполнен.

2) Также попробуйте NSLog(@"%d",[table count]);

Я думаювам лучше пойти с %d, а не %i.

Надеюсь, это вам поможет.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...