Note that there are some explanatory texts on larger screens.

plurals
  1. POSharing singleton data with several UIViewControllers data loss
    text
    copied!<p>I have a menu system made up of several UIViewControllers with focus being passed around by the NavigationController. Most of these controllers reference (if not manipulate) a singleton which is responsible for managing the courses in my game called CoursesManager &lt;- (not a UIViewController). The creating and editing systems work well, but I keep running into an issue where I lose data or receive an empty (junk data) array of courses resulting in a crash from CoursesManager when trying to update some labels in one of my UIViewControllers. This loss of data is always found in one of the following methods of one particular "problem" (UIViewController*)ProblemViewController: viewDidAppear, viewWillAppear, viewDidDisappear, and viewWillDisappear.</p> <p>My theory is that somehow data is still used by another UIViewController when ProblemUIViewController is trying to access it which results in bad data. I'm not really certain how to test or fix this though. I'm a little hazy on how threading works in iPhone programming in general as well. It also seems likely to me that this is the case since ProblemUIViewController is at the bottom of the NavigationController stack.</p> <p>Any help would be greatly appreciated.</p> <p><strong>EDIT</strong> Here is the error message I'm getting.</p> <blockquote> <p>-[CALayerArray isEqualToString:]: unrecognized selector sent to instance 0x2d31a0</p> <p><strong>* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayerArray isEqualToString:]: unrecognized selector sent to instance 0x2d31a0' *</strong> First throw call stack: (0x3262288f 0x34678259 0x32625a9b 0x32624915 0x3257f650 0x3204d3f9 0x3141f 0x3123b 0x3208bb95 0x320e58af 0x3208e913 0x3208e503 0x320d88eb 0x320d8719 0x320bcbc1 0x343cb 0x3257c3fd 0x32064e07 0x32064dc3 0x32064da1 0x32064b11 0x32065449 0x3206392b 0x32063319 0x32049695 0x32048f3b 0x316d022b 0x325f6523 0x325f64c5 0x325f5313 0x325784a5 0x3257836d 0x316cf439 0x32077cd5 0x22c1 0x2280) terminate called throwing an exception(lldb)</p> </blockquote> <p>This exception is getting thrown when the code enters this function.</p> <blockquote> <p>-(void)viewWillAppear:(BOOL)animated { [self refreshCourses]; [self toggleEditMode:NO]; }</p> <p>-(void)refreshCourses { struct SCourse* courses = [coursesManager GetAllCourses];</p> <pre><code>for(int i = 0; i &lt; MAX_COURSES; ++i) { // deactivate all buttons/labels courseButtons[i].hidden = YES; courseLabels[i].hidden = YES; deleteButtons[i].hidden = YES; // remake with current data if(courses[i].inUse == YES) { switch (courses[i].size) { case 1: [courseButtons[i] setImage:[UIImage imageNamed:@"sm_coursename_BG.png"] forState:UIControlStateNormal]; break; case 2: [courseButtons[i] setImage:[UIImage imageNamed:@"med_coursename_BG.png"] forState:UIControlStateNormal]; break; case 4: [courseButtons[i] setImage:[UIImage imageNamed:@"lg_coursename_BG.png"] forState:UIControlStateNormal]; break; default: break; } courseLabels[i].text = courses[i].name; // exception thrown here on second iteration of loop with 2 courses to loop through courseLabels[i].hidden = NO; courseButtons[i].hidden = NO; } // if } // for } </code></pre> <p>-(void)toggleEditMode:(BOOL)bMode {</p> <pre><code>bEditMode = bMode; if (bMode == YES) { for (int i = 0; i &lt; MAX_COURSES; ++i) { if(courseButtons[i].hidden == NO) { struct SCourse tempCourse = [coursesManager GetCourseAtIndex:i]; courseLabels[i].text = [NSString stringWithFormat:@"(edit) %@", tempCourse.name]; deleteButtons[i].hidden = NO; } } } else // bMode == NO { for (int i = 0; i &lt; MAX_COURSES; ++i) { if (courseButtons[i].hidden == NO) { struct SCourse tempCourse = [coursesManager GetCourseAtIndex:i]; courseLabels[i].text = tempCourse.name; } deleteButtons[i].hidden = YES; } } } </code></pre> </blockquote> <p><strong>Method of the singleton being called to get all the courses:</strong></p> <blockquote> <p>-(struct SCourse*)GetAllCourses { return courses; }</p> </blockquote> <p>coursesManager is my singleton which holds all the data.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload