2012-02-22 5 views
0

は私がしたい奇妙な行動2でも、私はそれだけで1行が含まれていると言うので、私はのUITableView行レンダリング

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    NSLog(@" I entered numberOfSectionsInTableView"); 
    return 2; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {   
    if (section = 0) { 
     1; 
    } 
    else { 
     9; 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    NSLog(@" I entered cellForRowAtIndexPath"); 
    NSLog(@"the Caf files count is : %d",[self.CafFileList count]); 
    NSLog(@" the txt file %d",[self.TXTFileList count]); 
    if (indexPath.section == 0) { // Enter here twice , even I say it contain only one row 
     NSLog(@"////////////////////////Section 0 %d" , [indexPath row]); 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 
     [[cell textLabel] setText:[self.TXTFileList objectAtIndex:[indexPath row] ] ];  
     return cell;  
    } 
    else if (indexPath.section == 0 && indexPath.row < [self.TXTFileList count] ){ 
     NSLog(@"////////////////////////Section 1 %d" , [indexPath row]); 
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (cell == nil) { 
      cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     } 
     [[cell textLabel] setText:[self.CafFileList objectAtIndex:[indexPath row]] ]; 
     return cell; 
    } 
} 

問題以下のコードをやったことが二度ここに入力していることであるのUITableView 2つのセクションを作成

if (indexPath.section == 0) { 

+2

をクラッシュさせたり、間違っているだろうに見えますか?そして1。 :-) –

+0

申し訳ありませんUをもっと説明できます – AMH

答えて

4

あなたはnumberOfRowsInSectionに行番号を返さないことを解決するためにどのように任意のアイデア、あなただけの番号を入力しますが、何も返しません。

また、

if (section = 0) { 

セットsection 0に、あなたは==演算子を使用します。

+0

if(section = 0){ – AMH

+1

あなたの 'numberOfRowsInSection:'関数はこれを行います。 =演算子は代入演算子です。==に変更する必要があります。これは比較演算子 – JiaYow

+0

ですが、その部分は返されませんでした – AMH

3
if (section == 0) { 
    return 1; 
} 
else { 
    return 9; 
} 

また、あなたのコード:

else if (indexPath.section == 0 && indexPath.row < [self.TXTFileList count] ){ 

あなたはセクション== 1.セルを生成することはありません{(セクション= 0)場合は再利用セル

関連する問題