我正在尝试将3个对象传递给另一个VC,但它们在目标VC中显示为Null。
VC1:
- (void)specificExerciseTableViewController:(SpecificExerciseTableViewController *)specificExerciseTableViewController didSelectSpecificExerciseWithURL:(NSString *)exerciseURL muscleName:(NSString *)muscleName muscleURL:(NSString *)muscleURL;
{
[self addExercise];
}
-(void)addExercise
{
PFObject *exerciseInRoutine = [[PFObject alloc] initWithClassName:@"exerciseInRoutine"];
[exerciseInRoutine setObject:self.selectedExercise forKey:@"name"];
[exerciseInRoutine setObject:self.muscleName forKey:@"muscle"];
[exerciseInRoutine setObject:self.muscleURL forKey:@"picture"];
[exerciseInRoutine saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
[self.tableView reloadData];
} else {
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
}
将对象传递给VC1的类:
if ([self.delegate respondsToSelector:@selector(specificExerciseTableViewController:didSelectSpecificExerciseWithURL:muscleName:muscleURL:)])
{
NSString *exerciseName = [[self.exerciseArray objectAtIndex:selectedRowIndex.row] objectForKey:@"exerciseName"];
[self.delegate specificExerciseTableViewController:self didSelectSpecificExerciseWithURL:exerciseName muscleName:self.muscleName muscleURL:self.muscleURL];
[self dismissModalViewControllerAnimated:YES];
}
编辑:
我已经更新了我的方法,将对象设置为VC的属性,但是有同样的问题:
- (void)specificExerciseTableViewController:(SpecificExerciseTableViewController *)specificExerciseTableViewController didSelectSpecificExerciseWithURL:(NSString *)exerciseURL muscleName:(NSString *)muscleName muscleURL:(NSString *)muscleURL;
{
self.muscleName = exerciseURL;
self.muscleName = muscleName;
self.muscleURL = muscleURL;
[self addExercise];
}
答案 0 :(得分:0)
执行上面显示的代码时,您期望发生什么?
第二个代码块在某些-specificExerciseTableViewController:didSelectSpecificExerciseWithURL:muscleName:muscleURL:
上调用delegate
,但在“VC1”示例中该方法的实现忽略了传递给该方法的参数。您似乎没有对您提供的数据做任何事情。
答案 1 :(得分:0)
问题是你是将参数传递给delgate对象。但是在委托方法中你没有将参数传递给函数addExercise,或者在调用方法之前将参数分配给你的属性。