Ios “如何隐藏”;“下一步”;没有检查单元格时按下按钮?
在没有检查单元格的情况下,如何隐藏“下一个”按钮。但当我选中min 1 cell时,“下一步”按钮应该可用 这是我的didselectedrow:Ios “如何隐藏”;“下一步”;没有检查单元格时按下按钮?,ios,xcode,checkbox,tableview,Ios,Xcode,Checkbox,Tableview,在没有检查单元格的情况下,如何隐藏“下一个”按钮。但当我选中min 1 cell时,“下一步”按钮应该可用 这是我的didselectedrow: - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSManagedObjectContext *context = [app managedObjectContext]; StandortCell
- (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();
}
}
当我尝试代码时,下一个按钮消失,但当我选择多个单元格并取消选择一个单元格时,下一个按钮消失。当未选择任何单元格时,它应消失。当构建视图时,添加按钮:
- (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个):
取消选择某一行时,将调用该行,如果没有选定行,则禁用rightbarbutton:
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView indexPathsForSelectedRows] == nil) {
self.navigationItem.rightBarButtonItem.enabled = NO;
}
}
当我选择几个单元格并再次取消选择它们时,按钮没有再次隐藏:(这是因为只有在选中一行时才会调用此方法。使用我现在添加的方法。我想你不明白我的问题。当视图打开时,“下一步”按钮隐藏,在我点击“最小1个单元格”后,它会显示一个复选标记,“下一步”按钮可见。但是,当我取消选择所有选定单元格时,复选标记消失但是“下一步”按钮仍然可见HMMM您可以试试吗?它不会删除按钮,但会使按钮不可用并变灰。您也可以像在代码示例中那样删除按钮,然后在再次需要时重新生成它们。
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView indexPathsForSelectedRows] == nil) {
self.navigationItem.rightBarButtonItem.enabled = NO;
}
}