我的程序:
我有视图parentView
和childView
. childView
有一个UITextField
。这UITextField
是由用户完成的。然后通过 aUITextField.text
作为 aNSString
传递。Notification 方法中的 表示该值已成功传递给。parentView
NSNotificationCenter
NSLog
parentView
现在的问题....当我尝试_guideDescription
在我的应用程序中访问(包含正在传递的值)时saveIntoExisting
崩溃。我不明白为什么当它能够检索通知方法中的值时会崩溃。
没有错误只是(llbs)
。
任何人都知道为什么会这样?
- (void)viewWillAppear:(BOOL)animated {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(notificationSelectedDescription:)
name:@"selectedDescription"
object:nil];
}
- (void) notificationSelectedDescription:(NSNotification *)notification {
_guideDescription = [[notification userInfo] valueForKey:@"selected"];
NSLog(@"Show me: %@",[_guideDescription description]);
}
- (IBAction)createExercise:(UIButton *)sender {
if (![self fetch]) {
NSLog(@"It doesnt exist already");
[self save];
} else {
NSLog(@"It does exist already");
/*
* ADD CODE ON HOW TO ACT WHEN EXISTS
*/
[self saveIntoExisting];
}
}
- (void) saveIntoExisting {
NSLog(@"saveintoExisting 1");
NSLog(@"saveintoExisting show me: %@",[_guideDescription description]);
NSFetchRequest *fetchExercise = [[NSFetchRequest alloc] init];
NSEntityDescription *entityItem = [NSEntityDescription entityForName:@"Exercise" inManagedObjectContext:context];
[fetchExercise setEntity:entityItem];
[fetchExercise setPredicate:[NSPredicate predicateWithFormat:@"exerciseName == %@",_originalExerciseName]];
[fetchExercise setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"User", nil]];
fetchExercise.predicate = [NSPredicate predicateWithFormat:@"user.email LIKE %@",_appDelegate.currentUser];
NSError *error = nil;
NSArray* oldExercise = [[context executeFetchRequest:fetchExercise error:&error] mutableCopy];
Exercise *newExercise = (Exercise*) oldExercise[0];
newExercise.exerciseName = _exerciseName.text;
newExercise.exercisePic = _selectedImage;
if (![_guideDescription isEqualToString:@""]) {
newExercise.exerciseDescription =_guideDescription;
}
if (_youTubeLink){
newExercise.youtube =_youTubeLink;
}
if (![_selectRoutine.titleLabel.text isEqualToString:@"add to routine"]) {
newExercise.routine = [[self getCurrentRoutine] exercise];
[[self getCurrentUser] addRoutines:[[self getCurrentRoutine] exercise]];
}
[[self getCurrentUser] addExercisesObject:newExercise];
error = nil;
[context save:&error ];
}