OK, so here's my newest problem. I have a bunch of UIButtons, all laid out in the same XIB file. Each one has a superview with a unique tag. This tag is used to decide whether the button shows up. At any one time, there should be one, and only one such button on the screen. Their superviews are hidden in viewDidLoad, then un-hidden on an as-needed basis.
What I'm finding thus far is that sometimes, after clicking the button and segueing to a different view controller, when that view controller then segues back to the screen, there are two buttons. When I then close the app and go back to that screen, I go back to seeing only one.
Furthermore, in one related case - when I load the app and go directly to the screen - the wrong UIButton shows up!
My numbering system appears to be adequate for the task at hand. One user suggested using NSUserDefaults, but - for a reason I won't be mentioning - I'm using Core Data to identify which button should be showing.
Here's my toggle code:
What I'm finding thus far is that sometimes, after clicking the button and segueing to a different view controller, when that view controller then segues back to the screen, there are two buttons. When I then close the app and go back to that screen, I go back to seeing only one.
Furthermore, in one related case - when I load the app and go directly to the screen - the wrong UIButton shows up!
My numbering system appears to be adequate for the task at hand. One user suggested using NSUserDefaults, but - for a reason I won't be mentioning - I'm using Core Data to identify which button should be showing.
Here's my toggle code:
Code:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Get an array of all menu item views for activities up to, and including, the current activity.
NSInteger placeTag = entity.familyNum * 10 + entity.activityNum;
NSPredicate *filteringPredicate = [NSPredicate predicateWithBlock:^BOOL(id obj1,NSDictionary *dictionary) {
return [obj1 isKindOfClass:[MenuItemView class]];
}];
NSArray *filteredViews = [levelView.subviews filteredArrayUsingPredicate:filteringPredicate];
// Loop through all views for activities up to, and including, current activity.
for (int representedFamily = 0; representedFamily <= entity.familyNum; representedFamily++) {
for (int representedActivity = 0; representedActivity <= entity.activityNum; representedActivity++)
{
NSInteger thisViewTag = representedFamily * 10 + representedActivity; // Tag of the view corresponding to represented family and activity.
// Find view with thisViewTag
MenuItemView *thisView = [[filteredViews filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(MenuItemView *view, NSDictionary *dictionary) {
return view.tag == thisViewTag;
}]] firstObject];
NSAssert(thisView != levelView, @"levelView is thisView - change levelView's tag");
NSAssert(thisView != nil,@"Nil levelView!");
thisView.hidden = false;
if (thisViewTag == placeTag) {
// Current activity
currentActivityTag = thisViewTag;
thisView.userInteractionEnabled = true;
thisView.button.hidden = false;
thisView.button.userInteractionEnabled = true;
[thisView.button addTarget:self action:@selector(activityButtonPressed:) forControlEvents:UIControlEventTouchDown];
}
else
{
NSAssert(thisView.button != nil, @"Nil view button!");
// Past activity
//Breakpoint here fires only once
thisView.button.hidden = true;
thisView.button.userInteractionEnabled = false;
thisView.starImageView.hidden = false;
}
}
}
}
Last edited: