I have a form that the user submits, he must reload the view (but change a few things).
This form has a UIPickerview (_tripPicker) in which there are 2 locations, a source location and an end location (2 components to choose from).
I have it saved in the appropriate database and all that - but when it reboots (when the user clicks on save), I want pickerview to be "reset" and the first place (begSchool) to match the users of the second location (endSchool) they just saved in coredata.
For example: Assume that the user has moved from PointB to pointC (components 0 and 1 respectively in pickerview); when they click "Save", I would like component 0 to display "PointC", and for the second component, just display a list of points that you need to go to (resetting it before it initially loads).
I tried to execute some of the relevant lines, but I have problems with it.
Here is the logic where I do this:
[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreWithCompletion:^(BOOL success, NSError *error) {
NSArray *tripsSorted = [UserMiles MR_findAllSortedBy:@"driven_date" ascending:NO];
if (!tripsSorted || !tripsSorted.count){
begSchoolLabel.text = [_schoolArray1 objectAtIndex:[_tripPicker selectedRowInComponent:0]];
} else {
UserMiles *lastTrip = [tripsSorted objectAtIndex:0];
NSString *preValue = lastTrip.end_school;
begSchoolLabel.text = preValue;
NSUInteger *currentIndex = [_schoolArray1 indexOfObject:preValue];
[_tripPicker selectRow:currentIndex inComponent:0 animated:YES];
NSLog(@"LastTrip.endSchool = %@", lastTrip.end_school);
}
endSchoolLabel.text = [_schoolArray2 objectAtIndex:[_tripPicker selectedRowInComponent:1]];
NSLog (@"saveInBackground: finished!");
}];
[self.view setNeedsDisplay];
lastTrip.end_school gets me the corresponding school name from pickerview component 1, I just need to figure out how to match this with the corresponding value from the array that pickerview loads and makes it selected in pickerview. The text currently displays the corresponding name, but pickerview doesn't show any changes.
, , - .