2012-04-14 16 views
0

私はuitableviewを作成しました。起動すると、それは想定どおりに見えますが、スクロールすると、指定しない他のすべてのセクションにテキストが表示されます。助けてください。 添付されている最初のイメージは、どのように見えるかです。二番目はスクロールするときの動作です。スクロールするときにUITableViewセルのラベルが移動する

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    if (section == 0){ 
     return 1;} 
    else if (section == 1){ 
     return [cellLabels count]; 
    }else if (section == 2){ 
     return 1; 
    }else{ 
     return 0; 
    } 

} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *cellIdentifier = @"cellIdentifier"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; 
    } 
    tableView.showsVerticalScrollIndicator = NO; 
    // cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 


    if(indexPath.section == 0) 
    { 
    } 
    else if (indexPath.section == 1) 
    { 
     cell.textLabel.backgroundColor = [UIColor clearColor]; 
     cell.textLabel.textColor = [UIColor blackColor]; 
     // headerLabel.font = [UIFont SystemFontOfSize:16]; 
     [cell.textLabel setFont:[UIFont fontWithName:@"Arial" size:14]]; 
     cell.textLabel.text = [cellLabels objectAtIndex:indexPath.row]; 


    } 
return cell; 

} 

This is what is looks like when it is launched, and what it is supposed to look like

enter image description here

答えて

1

それは第二に、最初のセクションあなたの表示何にも初めてになると、テーブルビューが細胞、 を割り当てられた再利用しので、あなたの問題は、

非常に単純ですカスタムテキストを表示するセクション

スクロールダウンしてcそれは

if(indexPath.section == 0) 
{ 
} 

に到達したとき、それはとても

を何でもする文句を言わないので、OME戻ってそれはテキストが

if(indexPath.section == 0) 
{ 
    cell.textLabel.text = @""; 
} 
else if(indexPath.section == 2) 
{ 
    cell.textLabel.text = @""; 
} 

または

SECTION 1 FOR他
if(indexPath.section == 0) 
{ 
    cell.textLabel.text = nil; 
} 

else if(indexPath.section == 2) 
{ 
    cell.textLabel.text = nil; 
} 

作る最初のセクションに表示されます正しいです。

関連する問題