0

THX FOR THE HELP!

I changed the Viewdidload like that and it is working fine for me now! Iam Fetching the location and took a predicate to synchronize the checks and the state of the button

  - (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;
    }
Bashud
  • 266
  • 2
  • 8
  • 20
  • you can make a bool property that is directly mapped with your tableview cell, when you select the cell its value will become yes and vice versa. Now based on this bool variable you can also enable/disable next button. – rishi Apr 23 '12 at 09:17
  • @RIP - only the next button state depends on the values of all cells. (e.g. even if you uncheck a cell, but another cell is still checked, it should still be enabled) – MByD Apr 23 '12 at 09:21
  • @BinyaminSharet - what i mean is keeping track of all cells. Like you did. :) – rishi Apr 23 '12 at 17:12

1 Answers1

2

Add a check counter as an instance member, and initialize it to 0, on each check increase it, and on each uncheck decrease it, after each check set the button:

- (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
}
MByD
  • 135,866
  • 28
  • 264
  • 277
  • @Bashud - iterate over the state of all cells in viewDidLoad and update the counter. – MByD Apr 23 '12 at 10:20