2012-02-12 18 views
0

3つのセクションで構成されるグループ化されたUITableViewがあります:3つのうち2つは定数です(各セルは1つしか変更されません)。細胞。このセクションからセルを削除すると、すべてが完璧に機能します。最後のセルを削除すると、このセルは消えます(期待通り)が、他のセクションは機能しません。つまり、クリックできません。最初のセクションが最初に空のときにアプリケーションを読み込むと、すべて正常です。このことは、このセクションの最後のセルを削除した後にのみ発生します。私はコードのどこにでもログを入れようとしましたが、すべてが大丈夫です。最後のセルを削除した後にUITableViewセルが選択されない

ご意見がありがとうございます。

ここに関連性のあるコードがあります。

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (indexPath.section == 0) { 
    return YES; 
} else { 
    return NO; 
} 
} 


- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

[tblSimpleTable beginUpdates]; 

if (editingStyle == UITableViewCellEditingStyleDelete) { 

    NSMutableArray * section = [listOfItems objectAtIndex:indexPath.section];  
    [section removeObjectAtIndex:indexPath.row]; 

    //UPDATING USERS DEFAULTS 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];    
    [defaults setObject:section forKey:@"listOfAccessNumbers"]; 

    [tblSimpleTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight]; 
    [tblSimpleTable reloadData]; 


    } 


}  
else if (editingStyle == UITableViewCellEditingStyleInsert) { 

... 

} 

[tblSimpleTable endUpdates]; 

} 


- (void)setEditing:(BOOL)editing animated:(BOOL)animated { 

NSLog(@"****************** entering setEditing"); 

[super setEditing:editing animated:animated]; 
[tblSimpleTable setEditing:editing animated:YES]; 
if (editing) { 
    editButton.enabled = NO; 
} else { 
    editButton.enabled = YES; 
} 
} 

UPDATE:複数のメソッドを追加:

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

NSLog(@"****************** entering cellForRowAtIndexPath"); 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; //try here diff styles 
} 


NSArray *array = [[NSArray alloc] init]; 
array = [listOfItems objectAtIndex:indexPath.section]; 
NSString *cellValue = [array objectAtIndex:indexPath.row]; 
cell.textLabel.text = cellValue; 
cell.textLabel.font = [UIFont systemFontOfSize:14]; 
cell.selectionStyle = UITableViewCellSelectionStyleNone; 
cell.textLabel.textColor = [UIColor colorWithRed:.196 green:0.3098 blue:0.52 alpha:1.0]; 

if (sectionIndicator == YES){ 

    if (indexPath.section == 0) { 
     cell.accessoryType = UITableViewCellAccessoryNone; 
    } 
    else if (indexPath.section == 1) { 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

} 
else 
{ 
    if (indexPath.section == 0) { 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 
    else if (indexPath.section == 1) { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
} 


return cell; 
} 




- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 

return [listOfItems count];  
} 



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 

return [[listOfItems objectAtIndex:section] count]; 
} 
+0

'numberOfSectionsInTableView:'と 'tableView:numberOfRowsInSection:'メソッドでケースを適切に処理していますか? – msgambel

+0

commitEditingStyleメソッドの 'beginUpdates'と' endUpdates'は必ずしも必要ではありません。それらを削除して問題が解決したかどうかを確認することは価値があります。そうでない場合は、問題はtableView:cellForRowAtIndexPath:メソッドまたはdataSourceメソッドのいずれかに関連付けられている可能性が最も高いです。 – justin

+0

はい、私は理解していますテーブルが正しく描画されます(3つのセクション、1つはセルがない「空」、もう1つはセルが1つの2つのセクション)。 – TommyG

答えて

0

私は何が起こっているか知っているかもしれないと思うので、回答として投稿します。

listOfItemsを呼び出して、アイテムを削除する一時配列を取得していることに気付きました。私はまたあなたがNSUserDefaultsのオブジェクトを更新しているのを見ています。これが行われた後、listOfItemsも更新されますか?そうでなければ、問題がどこにあるのでしょうか。前と同じ情報を保持し続けるので、更新が発生していないかのように見えます。私はこれが事実であることを願っています。なぜなら、それはあなたの部分で非常に簡単な修正をするためです。そうでない場合は、問題がどこにあるのかを確認するためには、dataSourceメソッドを参照する必要があります。

+0

私は驚いていましたが、「[removeObjectAtIndex:indexPath.row]セクション;」 listOfItemsからもエントリを削除しますので、問題ありません...ありがとう – TommyG

+0

確かに奇妙です。'tableView:cellForRowAtIndexPath:'、 'numberOfSectionsInTableView:'、 'tableView:numberOfRowsInSection:'メソッドを見ることができます。 'listOfItems'が問題ではない場合、私はこれらのメソッドのいずれかに問題があると賭けています – justin

+0

ここでは、それらのメソッドをすべて追加しました。私はそこに何かが間違っているとは思っていません....まだこれを修正することはできません、...:/ – TommyG

0

beginUpdatesendUpdatesreloadDataを呼び出さないでください必要に応じて、より多くのを提供して幸せ。 reloadDataに電話する必要があるかどうかはわかりませんが、に電話する必要があるかどうかを確認するために、endUpdatesに電話した後に、いつでもブール値フラグをbeginUpdatesの範囲内でtrueに設定してフラグを確認できます。

+0

reloadData does not help。 – TommyG

関連する問題