2012-01-02 17 views
1

UITableView内の各セルのテキストが表示されていないため、私の人生の間、その理由を理解できません。私はテーブルビューに3つのセクションがあり、セクションは各セクションの行数と同様に正しく表示されます。ただし、すべてのセクションの各行内のテキストは空です。私のコードは次のとおりです。代わりに、非推奨initWithFrameのグループ化されたUITableViewにテキストが表示されない

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

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を印刷しようとしたことがありを(@ "Value:%@"、cellValue]; cellValueがその時点でnilでないことを確認するためのセル作成メソッドでは? –

答えて

1

、作成した辞書は、 "国が" あなたは で使用しているWICH @キー持っていけない - (UITableViewCellの*)のtableView:(のUITableView *)のtableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

+0

haha​​ yup!それほどありがとうございました。私は書いた別のアプリからそれをコピーし、私の校正技術はその行を何度も見逃していました。ありがとう! – Prajoth

1

を持つ細胞のためのあなたのinitメソッドを変更してみてください。

また、設定しようとしている文字列がnilでないことを確認してください。

+0

私はちょうどその文字列がゼロであることを認識しました。私のviewDidLoadの配列。どのように私のUITableViewに印刷する配列を取得するのですか?明らかに、私はcellForRowでやったやり方は間違っています。ありがとう! – Prajoth

+0

cell.textLabel.textとしてテキストを設定するのが正しい方法ですデフォルトそこに何かを設定している限り、それが表示されるはずですあなたの細胞に –

関連する問題