2012-04-18 11 views
0

セルがチェックされていないときにどうすれば 'next'barbuttonitemを非表示にできますか?しかし、1分のセルをチェックすると、次のボタンが利用可能になるはずです。セルがチェックされていないときに "次の"バーを非表示にする方法は?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSManagedObjectContext *context = [app managedObjectContext]; 
    StandortCell *cell = (StandortCell *)[tableView cellForRowAtIndexPath:indexPath]; 
    Standort *standort=[self.fetchedResultsController objectAtIndexPath:indexPath]; 
    NSLog(@"Ausgewaehlte Standort %@",standort.ort); 

    if (cell.checkButton.hidden==YES){ 
     cell.checkButton.hidden=NO; 
     UIBarButtonItem *myWeiter = [[UIBarButtonItem alloc] initWithTitle:@"Weiter" style:UIBarButtonItemStyleBordered target:self action:@selector(nextPressed:)]; 
     UIBarButtonItem *myMapButton = [[UIBarButtonItem alloc]initWithTitle:@"Karte" style:UIBarButtonItemStyleBordered target:self action:@selector(mapPressed:)]; 

     NSArray *myButtonArray = [[NSArray alloc] initWithObjects:myWeiter,myMapButton,nil]; 

     self.navigationItem.rightBarButtonItems = myButtonArray; 
    }else { 
     cell.checkButton.hidden=YES; 
     self.navigationItem.rightBarButtonItem = nil; 
     UIBarButtonItem *myMapButton = [[UIBarButtonItem alloc]initWithTitle:@"Karte" style:UIBarButtonItemStyleBordered target:self action:@selector(mapPressed:)]; 

     NSArray *myButtonArray = [[NSArray alloc] initWithObjects:myMapButton,nil]; 

     self.navigationItem.rightBarButtonItems = myButtonArray; 
    }  

    if ([[standort valueForKey:@"ortcheck"] boolValue]) { 
     [standort setValue:[NSNumber numberWithBool:NO] forKey:@"ortcheck"]; 

    } else { 

     [standort setValue:[NSNumber numberWithBool:YES] forKey:@"ortcheck"]; 

    } 


    NSError *error = nil; 
    if (![context save:&error]) { 

     NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
     abort(); 
    } 




} 

私は自分のコードをしようとすると、nextbuttonが消えるが、私は複数のセルを選択して、1の選択を解除したときに、nextbuttonが消える:

は、ここに私のdidselectedrowです。ビューが構築されるときにセルが

答えて

0

が選択されていないときにボタンを追加消えるはず:

- (void)viewDidLoad { 
    UIBarButtonItem *myWeiter = [[UIBarButtonItem alloc] initWithTitle:@"Weiter" style:UIBarButtonItemStyleBordered target:self action:@selector(nextPressed:)]; 
    UIBarButtonItem *myMapButton = [[UIBarButtonItem alloc]initWithTitle:@"Karte" style:UIBarButtonItemStyleBordered target:self action:@selector(mapPressed:)]; 

    NSArray *myButtonArray = [[NSArray alloc] initWithObjects:myWeiter,myMapButton,nil]; 

    self.navigationItem.rightBarButtonItems = myButtonArray; 
} 

を行が選択を取得したときにボタンが常に表示されなければならない(少なくとも1の選択があるように):

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    self.navigationItem.rightBarButtonItem.enabled = YES; 
} 

行の選択が解除されますとき、これが呼び出され、存在する場合は何も選択された行はrightbarbuttonを無効にしない:

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if ([tableView indexPathsForSelectedRows] == nil) { 
     self.navigationItem.rightBarButtonItem.enabled = NO; 
    } 
} 
+0

いくつかのセルを選択すると再び選択解除され、ボタンは再び非表示になりませんでした。( –

+0

)このメソッドは行が選択されたときにのみ呼び出されるためです。今追加するメソッドを使用します。 – Manuel

+0

あなたは私の質問を理解していないと思います。ビューが開いているときに、次のボタンが非表示になります。最小1個のセルをタップすると、チェックマークが表示され、次のボタンが表示されます。選択したセルをすべて選択解除すると、チェックマークは消えますが、次のボタンは引き続き表示されます –

関連する問題