0

感谢您的帮助!

我像那样更改了 Viewdidload,现在它对我来说工作正常!我正在获取位置并使用谓词来同步检查和按钮的状态

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

1 回答 1

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
}
于 2012-04-23T09:15:17.810 回答