2009-07-06 5 views
-1

セクションを作成すると、エラーが発生します。UITableviewセクションエラー - objc_msgSend

私は既にセクションインデックスを0と1に設定しようとしましたが、どちらも役に立ちませんでした。

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

    static NSString *CellIdentifier = @"Cell"; 
    static NSString *CellIdentifier1 = @"Cell1"; 


    if(indexPath.section == 1) { 
     if(indexPath.row == 0) { 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     cell.text = @"test 1"; 

     } 

     return cell; 
    } 
    else if(indexPath.row == 1) { 
     UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell1 == nil) { 
      cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
      cell1.text = @"test 2"; 

     } 

     return cell1; 
    } 
    } 

else if(indexPath.section == 2) { 
    if(indexPath.row == 0) { 

     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
      cell.text = @"test 1"; 

     } 

     return cell; 
    } 
    else if(indexPath.row == 1) { 
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
     if (cell1 == nil) { 
      cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
      cell1.text = @"test 2"; 

     } 

     return cell1; 
    } 
} 
} 

答えて

0

セクションと行は私の知る限り見ることができるように0から始まり、あなたはセクション0にindexPathのためのセルを返さない、行0

編集:再投稿のソースコード(より読みやすい):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    static NSString *CellIdentifier1 = @"Cell1"; 
    if(indexPath.section == 1) { 
     if(indexPath.row == 0) { 
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
      if (cell == nil) { 
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
       cell.text = @"test 1"; 
      } 
      return cell; 
     } 
     else if(indexPath.row == 1) { 
      UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
      if (cell1 == nil) { 
       cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
       cell1.text = @"test 2"; 
      } 
      return cell1; 
     } 
    } 
    else if(indexPath.section == 2) { 
     if(indexPath.row == 0) { 
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
      if (cell == nil) { 
       cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
       cell.text = @"test 1"; 
      } 
      return cell; 
     } 
     else if(indexPath.row == 1) { 
      UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1]; 
      if (cell1 == nil) { 
       cell1 = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier1] autorelease]; 
       cell1.text = @"test 2"; 
      } 
      return cell1; 
     } 
    } 
} 
+0

セクションは実際には1から始まります。 ' - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView'関数は常に少なくとも '1'ではなく '0'を返します。これはクラッシュの原因にもなります。 – Jake

+1

実際には常に1つのセクションですが、インデックスパスの最初のセクションの番号はゼロですか? indexPath.section == 0 - >最初のセクション – drvdijk

+0

+1 - コンパイラは、(非void)関数を通るパスのどれかが何も返されないという事実についてコンパイラが警告するはずです。 – frankodwyer

0

基本的な質問。 Uは - (NSInteger)tableView:(UITableView *)のtableView numberOfRowsInSection:(NSInteger)セクションのセクション数を更新しました。 通常のobj msg送信エラーは、リリースしたものや所有していないものを処理している場合に発生します。 たとえば... このコードを使用すると、このコード のセクションの初期メソッドでセクション配列= [NSArray arraywithcontentsoffile:xyz.plist]

そしてRowsInSectionの数では、このようなものを使用します。 [セクション配列数];

ここで、sectionArrayはインスタンス変数です。

-1

あなたの返信ありがとうございます!

私はコード全体をもう一度書き、1行のコードを追加するたびに実行しました。それが助けになりました。 私は問題がif(indexPath.section == 0)であったと思います。 3つのセクションのうち2つのコンテンツのみを設定します。

しかし、私はwheatherがこれが問題であるかどうかはわかりません。

大変ありがとうございます!

初心者の目的は簡単ではありません:)