2012-04-19 4 views
0

У меня есть контроллер вида, который отображает контроллер табличного представления при нажатии кнопки. Все отлично работает с делегатами табличного представления, представление таблицы отображается в порядке, но в методе ellForRowAtIndexPath: delegate, экземпляр объекта и возвращается, но он не показан правильно.В представлении таблицы не отображаются пользовательские ячейки

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

    static NSString *CellIdentifier = @"alrededor"; 

    alrededorCell *cell = [tableView 
          dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     cell = [[alrededorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 


    NSDictionary *categoria = [[NSDictionary alloc] initWithDictionary: [_categoriasArray objectAtIndex:indexPath.row]]; 

    NSLog(@"categoria %@", categoria); 

    cell.title.text = [categoria valueForKey:@"title"]; 

    return cell; 

} 

Большое спасибо

+0

Что вы имеете в виду ** не отобразилась **? –

ответ

1

Если ячейка, которую вы загружаете, является подклассом UITableViewCell, и вы использовали построитель интерфейсов для создания ячейки, которую вы должны выполнить несколько вещей.

В файле nib удалите представление, которое есть при его создании, добавьте UITableViewCell и измените его класс на alrededorCell. Изменяет класс ячеек, а не владельца файла. Когда вы связываете кнопки, метки и т. Д. не забудьте связать их с ячейкой, а не с владельцем файла. Также установите cell uniqueIdentifier в alrededor.

В cellForRowAtIndexPath

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

    static NSString *CellIdentifier = @"alrededor"; 

    alrededorCell *cell = [tableView 
         dequeueReusableCellWithIdentifier:CellIdentifier]; 

    if (cell == nil) { 
     NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"nibName" owner:nil options:nil]; 
     for (alrededorCell *view in xib) { 
      if ([view isKindOfClass:[alrededorCell class]]) { 
       cell = view; 
      } 
     } 
    } 


    NSDictionary *categoria = [[NSDictionary alloc] initWithDictionary: [_categoriasArray objectAtIndex:indexPath.row]]; 

    NSLog(@"categoria %@", categoria); 

    cell.title.text = [categoria valueForKey:@"title"]; 

    return cell; 

} 
2

Почему вы создаете вашу клетку, как это?

if (cell == nil) { 
    cell = [[alrededorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

Если это ваши собственные клетки, почему вы используете UITableViewCellStyleDefault?

+0

Привет, какой из них правильный для пользовательских? Спасибо – theomen

+0

Проверьте это http://howtomakeiphoneapps.com/how-to-design-a-custom-uitableviewcell-from-scratch/1292/ –

Смежные вопросы