2012-01-02 2 views
1

Текст для каждой ячейки в UITableView не отображается, и я не могу на всю жизнь выяснить, почему. У меня есть 3 раздела в представлении таблицы, и разделы показаны правильно, равно как и количество строк для каждого раздела. Однако текст внутри каждой строки для всех разделов пуст. Мой код:Текст не отображается в Grouped UITableView

This is how its looking =[

- (void)viewDidLoad { 
      [super viewDidLoad]; 
      listofsections = [[NSMutableArray alloc] init]; 

      NSArray *shuffle = [NSArray arrayWithObjects: 
              @"Display words in alphabetical order", @"Display words in shuffled order", nil]; 
      NSDictionary *shuffleDict = [NSDictionary dictionaryWithObject:shuffle forKey:@"Object Key"]; 

      NSArray *wordFilter = [NSArray arrayWithObjects: 
           @"Show all words", @"Show words not yet appeared", @"Show words marked correct", @"Show words marked incorrect", @"Show words marked as favorite", @"Show words saved for later", nil]; 
      NSDictionary *wordFilterDict = [NSDictionary dictionaryWithObject:wordFilter forKey:@"Object Key"]; 

      NSArray *wordDisplay = [NSArray arrayWithObjects: 
           @"Display words first", @"Display definition first", nil]; 
      NSDictionary *wordDisplayDict = [NSDictionary dictionaryWithObject:wordDisplay forKey:@"Object Key"]; 

      [listofsections addObject:shuffleDict]; 
      [listofsections addObject:wordFilterDict]; 
      [listofsections addObject:wordDisplayDict]; 

      // Do any additional setup after loading the view from its nib. 
     } 

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

     return [listofsections count]; 
    } 


    // Customize the number of rows in the table view. 
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

     //Number of rows it should expect should be based on the section 
     NSDictionary *dictionary = [listofsections objectAtIndex:section]; 
     NSArray *array = [dictionary objectForKey:@"Object Key"]; 
     return [array count]; 
    } 

    - (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath { 

     //return UITableViewCellAccessoryDetailDisclosureButton; 
     return UITableViewCellAccessoryNone; 
    } 


    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 


     if(section == 0) { 
      return @"Word Display Order"; 
     } 
     if (section == 1) { 
      return @"Word Filter"; 
     } 
     else 
      return @"Display Selection"; 


    } 


    // Customize the appearance of table view cells. 
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

     static NSString *CellIdentifier = @"Cell"; 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 
     } 


     // Set up the cell... 

     //First get the dictionary object 
     NSDictionary *dictionary = [listofsections objectAtIndex:indexPath.section]; 
     NSArray *array = [dictionary objectForKey:@"Countries"]; 
     NSString *cellValue = [array objectAtIndex:indexPath.row]; 
     cell.textLabel.text = cellValue; 


     return cell; 
    } 

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
     [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    } 
+0

Вы пробовали печатать NSLog (@ «Значение:% @», cellValue], в методе создания ячейки, чтобы убедиться, что ваш cellValue в то время не равен нулю –

ответ

1

Вы создали словари не имеют ключ @ "Страны" которым вы использовали в - (UITableViewCell *) Tableview: (UITableView *) Tableview cellForRowAtIndexPath: (NSIndexPath *) indexPath

+0

haha ​​yup! Большое вам спасибо за это. Я скопировал его из другого приложения, которое я написал, и мои навыки коррекции пропустили эту строку несколько раз. Благодаря! – Prajoth

1

Попробуйте изменить метод инициализации для ячеек с:

cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 

вместо устаревшего initWithFrame.

А также убедитесь, что строка, которую вы пытаетесь установить, не равна нулю.

+0

Я просто понял, что строка равна нулю. Я добавляю содержимое строки каждой строки в массив в моем представленииDidLoad.Как я могу получить этот массив для печати в моем UITableView? Очевидно, способ, которым я это делал в cellForRow, неверен. Спасибо! – Prajoth

+0

Настройка текста как cell.textLabel.text - это правильный путь для дефолта UITableViewCells. Пока вы что-то устанавливаете, он должен появиться в ваших камерах. –

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