0

セルがチェックされていないときに「次の」バーボタン項目を非表示にするにはどうすればよいですか。しかし、最小1セルをチェックすると、次のボタンが利用できるはずです。

ここに私のdidselectedrowがあります:

- (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();
    }




}

コードを試してみると、次のボタンが消えますが、複数のセルを選択して選択を解除すると、次のボタンが消えます。セルが選択されていないときは消えるはずです

4

1 に答える 1

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;
}

行の選択が解除されると、これが呼び出され、選択された行がない場合は、右バーボタンを無効にします。

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([tableView indexPathsForSelectedRows] == nil) {
        self.navigationItem.rightBarButtonItem.enabled = NO;
    }
}
于 2012-04-18T07:33:57.827 に答える