我正在过渡到一个新的观点,我提出了新的观点,然后调用一个方法来加载一些数据:在我的球探报告视图调用另一个视图控制器的方法是造成循环
-(IBAction)switchToScoutingReport:(id)sender
{
InspectAppDelegate *dataCenter = (InspectAppDelegate *) [[UIApplication sharedApplication] delegate];
[self saveData];
ScoutingReportViewController *scoutingReport = [self.storyboard instantiateViewControllerWithIdentifier:@"ScoutView"];
[self setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:scoutingReport animated:YES];
[scoutingReport setScoutingEventData:[dataCenter.eventsArray objectAtIndex:0]];
}
控制器,它会调用这个方法:
-(void)setScoutingEventData:(ScoutingEventData *)scoutingEventDataInput
{
NSLog(@"setting event data");
self.scoutingEventData = scoutingEventDataInput;
[self loadDataWithEvent];
}
出于某种原因,这是我的输出:
2011-12-22 10:17:20.637 Inspect[329:207] setting event data
2011-12-22 10:17:20.637 Inspect[329:207] setting event data
2011-12-22 10:17:20.638 Inspect[329:207] setting event data
2011-12-22 10:17:20.638 Inspect[329:207] setting event data
2011-12-22 10:17:20.639 Inspect[329:207] setting event data
2011-12-22 10:17:20.640 Inspect[329:207] setting event data
2011-12-22 10:17:20.640 Inspect[329:207] setting event data
2011-12-22 10:17:20.641 Inspect[329:207] setting event data
这是ST在无限循环中。
我不知道为什么它的循环,没有循环代码来做到这一点。使用“set”方法有什么特别之处?我使用@property和@synthesize来创建scoutingEvenData。现在我想到了,我可以在我的其他视图控制器中设置scoutingEvenData。
但仍然感兴趣的是为什么此代码创建一个循环。有任何想法吗?
编辑:setScoutingEventData方法被调用,当我打电话loadDataWithEvent从其他类(setScoutingEventData从不直接调用任何控制器)循环....:/
哈哈,这是有道理的。我从来没有真正使用过setter方法,这个逻辑过程对我想要做的事情有意义。我改为直接在第一个控制器中直接设置self.scoutingEvenData并直接调用loadDataWithEvent。感谢您的解释。 – Padin215 2011-12-22 16:33:14