0

当没有检查单元格时,如何隐藏“下一个”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 消失,但是当我选择多个单元格并取消选择一个时,nextbutton 消失。当没有选择单元格时它应该消失

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 回答