2013-05-25 13 views
10

私はプログラムで作成されたUITableViewsを4つ持っています。 問題1:最初のセルは常に空白です。 問題2:スクロールダウンすると、一部のセルが空白になります。前後にスクロールすると、他のセルは消えます。私はUITableViewを作成する機能viewDidLayoutSubviews一部のUITableViewセルがスクロールダウンしてから消えた後に消えます

UITableView* channel_tableView[ TOTAL_TX_CHANNELS ]; 

:ここ

UITableViewsが作成されたコードであり、その細胞が... .mファイルの先頭で宣言UITableViews

アレイを設定されています:

for(int channel=0; channel < TOTAL_TX_CHANNELS; ++channel){ 
CGRect tableFrame = CGRectMake(x, y, width, height); 

channel_tableView[ channel ] = [[UITableView alloc]initWithFrame:tableFrame style:UITableViewStylePlain]; 

channel_tableView[ channel ].scrollEnabled = YES; 
channel_tableView[ channel ].userInteractionEnabled = YES; 
channel_tableView[ channel ].bounces = YES; 

channel_tableView[ channel ].delegate = self; 
channel_tableView[ channel ].dataSource = self; 

channel_tableView[ channel ].autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth; 
[channel_tableView[ channel ] reloadData];    // display channel's TableView 
[[self view] addSubview: channel_tableView[ channel ]]; 

}

各セルが設定されているのはここ

は、uは、辞書の1つの配列をタックして追加する必要が.......................

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"cellForRowAtIndexPath"); 
    NSLog(@" %d = row", indexPath.row ); 



    UITextView* test_textView; 
    UITextView* test_2nd_textView; 
    UITextView* test_3rd_textView; 


    // Determine which channel_tableView: 
     int channel; 
     for(channel = 0; channel < TOTAL_TX_CHANNELS; ++channel) 
     { 
      if(tableView == channel_tableView[ channel ]) 
       break; 
     } 
     // channel = tableView's channel 
     NSLog(@" %d = channel", channel ); 

    // DOCUMENTATION: Table View Programming Guide for iOS > Adding subviews to a cellís content view 

    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) 
    { 
     NSLog(@"  cell nil"); 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellIdentifier]; 
     /* Though it's UITableViewCellStyleDefault, the three defaults (image, label, detail label) are nil 
     if not set. */ 
    } 
     // Add UITextView for channel pipe to cell: 
      int pipe_width = 20; 
      int w = pipe_width; 
      int x = channel_tableView_width/2 - pipe_width/2; 
      int h = channel_row_height; 
      int y = 0; 
      test_textView = [[UITextView alloc] initWithFrame:CGRectMake (x,y, w,h)] ; 
      [test_textView setFont:[UIFont boldSystemFontOfSize:8.0]]; 
      [test_textView setEditable:NO]; 
      [test_textView setTextAlignment:NSTextAlignmentCenter]; 
      // Round the corners and set border color 
      if(channel == power_channel) 
       [test_textView setBackgroundColor:[UIColor greenColor]]; 
      else 
       [test_textView setBackgroundColor:[UIColor whiteColor]]; 
      [[test_textView layer] setBorderColor:[[UIColor blackColor] CGColor]]; 
      [[test_textView layer] setBorderWidth:1]; 
      //[[test_textView layer] setCornerRadius:15]; 
      [test_textView setClipsToBounds: YES]; 


     // Add UITextView for PWR RX to cell: 
     int PWR_RX_width = channel_tableView_width/2; 
     y = y + h ; 
     w = PWR_RX_width; 
     x = channel_tableView_width/2 - PWR_RX_width/2; 
     h = 20; 
      test_2nd_textView = [[UITextView alloc] initWithFrame:CGRectMake (x,y, w,h)]; 
      [test_2nd_textView setFont:[UIFont boldSystemFontOfSize:8.0]]; 
      [test_2nd_textView setEditable:NO]; 
      [test_2nd_textView setTextAlignment:NSTextAlignmentCenter]; 
      // Round the corners and set border color 
      [test_2nd_textView setBackgroundColor:[UIColor whiteColor]]; 
      [[test_2nd_textView layer] setBorderColor:[[UIColor blackColor] CGColor]]; 
      [[test_2nd_textView layer] setBorderWidth: 1]; 
      //[[test_2nd_textView layer] setCornerRadius:15]; 
      [test_2nd_textView setClipsToBounds: YES];  

     // Add UITextView for device to cell: 
     int device_width = channel_tableView_width/2; 
     y = y + h-3; 
     w = device_width; 
     x = channel_tableView_width/2 - device_width/2; 
     h = 40; 
      test_3rd_textView = [[UITextView alloc] initWithFrame:CGRectMake (x,y, w,h)]; 
      [test_3rd_textView setFont:[UIFont boldSystemFontOfSize:8.0]]; 
      [test_3rd_textView setEditable:NO]; 
      [test_3rd_textView setTextAlignment:NSTextAlignmentCenter]; 
      // Round the corners and set border color 
      [test_3rd_textView setBackgroundColor:[UIColor whiteColor]]; 
      [[test_3rd_textView layer] setBorderColor:[[UIColor blackColor] CGColor]]; 
      [[test_3rd_textView layer] setBorderWidth: 1]; 
      //[[test_3rd_textView layer] setCornerRadius:15]; 
      [test_3rd_textView setClipsToBounds: YES]; 

     /* 
       test_textView.tag = TEST_TEXTVIEW_TAG; 
       test_2nd_textView.tag = TEST_2ND_TEXTVIEW_TAG; 
       test_3rd_textView.tag = TEST_3RD_TEXTVIEW_TAG; 

     test_textView  = (UITextView*)[cell.contentView viewWithTag: TEST_TEXTVIEW_TAG]; 
     test_2nd_textView = (UITextView*)[cell.contentView viewWithTag: TEST_2ND_TEXTVIEW_TAG]; 
     test_3rd_textView = (UITextView*)[cell.contentView viewWithTag: TEST_3RD_TEXTVIEW_TAG]; 
     */ 
    //[test_textView setText:  [NSString stringWithFormat: @"pipe-%d", indexPath.row ]]; 
    [test_2nd_textView setText: [NSString stringWithFormat: @"PWR RX %d", indexPath.row ]]; 
    [test_3rd_textView setText: [NSString stringWithFormat: @"device %d", indexPath.row ]]; 
      // Add created UI objects to cell[ indexPath.row ]: 
       [cell.contentView addSubview:test_textView ]; 
       [cell.contentView addSubview:test_2nd_textView ]; 
       [cell.contentView addSubview:test_3rd_textView ]; 
    return cell; 
} 
+0

に役立つことがあります。 [NSString stringWithFormat:@ "セル%d"、シャネル]を試してみてください。 – Durgaprasad

答えて

14
あなたはベローのようなあなたの CellIdentifierを定義する必要があり

: -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *CellIdentifier = [NSString stringWithFormat:@"%d_%d",indexPath.section,indexPath.row]; 



    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 

    cell.textLabel.text = @"Test"; 
    cell.textLabel.textColor=[UIColor whiteColor]; 
    return cell; 
} 

NSString *CellIdentifier = [NSString stringWithFormat:@"%d_%d",indexPath.section,indexPath.row];

これはあなたがすべてのテーブルの同じcellIdentifierを使用しないでください、あなた

+1

ありがとう、Nitin!これにより、私は最終的にセルのデータ構造の動作を理解することができました。私の場合、私は4つのtableViewsを持っていたので、私のセル識別子はチャンネル番号と行番号の関数である必要があります。今すぐ値を変更せずにスクロールします。各テーブルの先頭の最初の行は、スクロールしてから戻っても常に空白です。しかし、NSLogは、行0がセルを取得することを示しています。 –

+0

こんにちはdauglasを参照してください:-http://stackoverflow.com/questions/6805669/ios-objective-c-only-the-first-cell-of-uitableview-doesnt-show-the-label-i-add –

+1

+1ありがとう、これは私を助けた – iMeMyself

0

ISあなたのtextfiledsデータは、スクロールテーブルビューの後にindexpath.rowを基にしています。

NSMutableDictionary *dicttable=[NSMutableDictionary dictionaryWithDictionary:[arrofselect  objectAtIndex:indexPath.row]]; 
    [dicttable setValue:[NSString stringWithFormat:@"%@",self.other_text.text] forKey:@"AnswerId"]; 
    [dicttable setValue:[[arrQuestions objectAtIndex:indexPath.row] valueForKey:@"QuestionID"] forKey:@"QuestionID"]; 
    [arrofselect replaceObjectAtIndex:indexPath.row withObject:dicttable]; 

uはその辞書ベースのindexapth.rowタグ値を置き換える必要があり、私の例で見たときに、テキスト編集

  • (無効)textFieldDidBeginEditing中:(UITextFieldの*)テキストフィールド
  • (無効)textFieldDidEndEditing:(UITextField *)textField

enjoy ... chee rs

+0

ご質問がある場合は... – Anjaneyulu

4

私には同じ問題がありましたが、私にとってはUITableviewCell内の要素のプロパティでした。カスタムセルを使用して、NIBまたはStoryBoardでテキストフィールドを作成することをお勧めします。その後、次のシグネチャを持つカスタムセルクラスでそれらのためのアウトレットを作成します。

@property (strong, nonatomic) IBOutlet UITextField *myText; 

重要な部分は弱い財産強いとされていない使用することです。

私の投稿にはlinkがあります。

幸運にも助けてください!

+0

実行時にセル内のUIオブジェクトの子供が変更されるため、私はストーリーボードを使用できませんでした。しかし、私は、ビルド時に各セルに正確に同じUIオブジェクトを設定し、実行時に必要なものを非表示にすることができたと思います。 –

関連する問題