如果没有选中单元格,我怎么能隐藏'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消失但是当我选择多个单元格并取消选择一个时,nextbutton消失。当没有选择单元格时它应该消失
答案 0 :(得分: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;
}
当选择一行时,按钮应始终可见(因为至少选择了一个):
- (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;
}
}