THX FOR THE HELP!
我改变了Viewdidload,现在它对我来说工作正常! Iam获取位置并使用谓词来同步检查和按钮的状态
- (void)viewDidLoad
{
[super viewDidLoad];
app = (AppDelegate *) [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [app managedObjectContext];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Standort" inManagedObjectContext:context];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ortcheck CONTAINS YES"];
[request setPredicate:predicate];
[request setEntity:entity];
NSError *error = nil;
NSArray *events = [context executeFetchRequest:request error:&error];
int i = events.count;
if (i == 0) {
myWeiter = [[UIBarButtonItem alloc] initWithTitle:@"Weiter" style:UIBarButtonItemStyleBordered target:self action:@selector(nextPressed:)];
self.navigationItem.rightBarButtonItem = myWeiter;
self.navigationItem.rightBarButtonItem.enabled = NO;
}
else {
myWeiter = [[UIBarButtonItem alloc] initWithTitle:@"Weiter" style:UIBarButtonItemStyleBordered target:self action:@selector(nextPressed:)];
self.navigationItem.rightBarButtonItem = myWeiter;
self.navigationItem.rightBarButtonItem.enabled = YES;
}
答案 0 :(得分:2)
添加一个检查计数器作为实例成员,并将其初始化为0,每次检查增加它,并在每次取消检查时减少它,在每次检查后设置按钮:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// snip
//if (cell.checkButton.hidden==YES){
// cell.checkButton.hidden=NO;
//}else {
// cell.checkButton.hidden=YES;
//}
BOOL state = !cell.checkButton.hidden;
cell.checkButton.hidden=state; // simpler
self.counter += (state) ? 1 : -1;
[nextButton setEnabled: counter > 0];
// snap
}