Как я могу назвать контроллер навигации ячеек? - PullRequest
0 голосов
/ 20 июля 2011
 if (indexPath.row % 2 == 0) {
    // EVEN
    cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EvenCell"] autorelease];
        UIView *bg = [[UIView alloc] initWithFrame:cell.frame];

        UIColor *colour = [[UIColor alloc] initWithRed: (208.0/255.f) green: (231.0/255.f) 
                                                  blue: (241.0/255.f) alpha: 1.0];
        bg.backgroundColor = colour; 
        cell.backgroundView = bg;
        cell.textLabel.backgroundColor = bg.backgroundColor;
        [bg release];
        cell.textLabel.text = [items objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }

} else {
    // ODD

    cell = [tableView dequeueReusableCellWithIdentifier:@"OddCell"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"OddCell"] autorelease];
        UIView *bg = [[UIView alloc] initWithFrame:cell.frame];

        UIColor *colour = [[UIColor alloc] initWithRed: (143.0/255.f) green: (169.0/255.f) 
                                                  blue: (180.0/255.f) alpha: 1.0];
        bg.backgroundColor = colour;
        cell.backgroundView = bg;
        cell.textLabel.backgroundColor = bg.backgroundColor;
        [bg release];
        cell.textLabel.text = [items objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    }
} 

return cell;
}

это мои пользовательские ячейки. Первый - четный, второй - нечетный. Мой массив содержит 194 элемента, но когда я запускаю приложение, я вижу только 10, после 10-го оно переходит к первому элементу, снова давая мне те же 10 элементов. Кто-нибудь может сказать мне, что здесь не так?

Ответы [ 2 ]

2 голосов
/ 20 июля 2011

Попробуйте это.

if (indexPath.row % 2 == 0) {
// EVEN
        cell = [tableView dequeueReusableCellWithIdentifier:@"EvenCell"];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"EvenCell"] autorelease];
            UIView *bg = [[UIView alloc] initWithFrame:cell.frame];


        UIColor *colour = [[UIColor alloc] initWithRed: (208.0/255.f) green: (231.0/255.f) 
                                                  blue: (241.0/255.f) alpha: 1.0];
        bg.backgroundColor = colour; 
        cell.backgroundView = bg;
        cell.textLabel.backgroundColor = bg.backgroundColor;
        [bg release];
    }
        cell.textLabel.text = [items objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;


} else {
    // ODD

    cell = [tableView dequeueReusableCellWithIdentifier:@"OddCell"];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"OddCell"] autorelease];
        UIView *bg = [[UIView alloc] initWithFrame:cell.frame];

        UIColor *colour = [[UIColor alloc] initWithRed: (143.0/255.f) green: (169.0/255.f) 
                                                  blue: (180.0/255.f) alpha: 1.0];
        bg.backgroundColor = colour;
        cell.backgroundView = bg;
        cell.textLabel.backgroundColor = bg.backgroundColor;
        [bg release];
    }
        cell.textLabel.text = [items objectAtIndex:indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;


  } 

  return cell;
 }
1 голос
/ 20 июля 2011

Чтобы ваше представление отображало правильное количество строк, убедитесь, что -(NSUInteger)tableView:numberOfRowsInSection:(NSUInteger)section возвращает правильное число.(в вашем случае вы должны вернуть [items count]).

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