好的,真正的快速问题,如果我想在一个方法中传递视图控制器,这将是正确的方法(显然,两者似乎都有效) -
-(void)fetchedDataN:(UIViewController *)response
或
-(void)fetchedDataN:(ViewController *)response
编辑:这是澄清事情的完整代码
- (IBAction)nextButton:(id)sender {
activityN.hidden=NO;
[activityN startAnimating];
[self.view bringSubviewToFront:activityN];
[audioFile stop];
NSLog(@"HELL O");
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
Page04ViewController *viewControl=[[Page04ViewController alloc]initWithNibName:nil bundle:nil];
[self performSelectorOnMainThread:@selector(fetchedDataN:)
withObject:viewControl waitUntilDone:YES];
}); }
-(void)fetchedDataN:(UIViewController *)response{
if ([self interfaceOrientation] == UIDeviceOrientationLandscapeLeft) {
[self presentViewController:response withPushDirection:@"fromTop"];
// NSLog(@"landscape left");
}
else if([self interfaceOrientation] == UIDeviceOrientationLandscapeRight)
{
[self presentViewController:response withPushDirection:@"fromBottom"];
// NSLog(@"landscape right");
} }
答案 0 :(得分:2)
据推测,ViewController
是UIViewController
...
如果您尝试将UIViewController
传递给第二种方法,那将无效(编译器会抱怨),因为它无法保证您传递的实例属于正确的类。< / p>
如果您尝试将ViewController
传递给第一个可行的方法,因为编译器可以进行保证。
方法定义的正确性取决于你的意图 - 不知道,两者都不正确,它们只是不同......
对于您更新的问题,如果方法仅显示视图控制器,那么使用UIViewController
可以被认为是正确的,因为它是最通用且最灵活的选项。如果你想在将来更改方法以添加需要response
作为特定子类的其他功能,那么编译器会告诉你它不能保证类的类型正确。
答案 1 :(得分:0)
这是对的:
-(void)fetchedDataN:(UIViewController *)response
。
然后你可以
-(void)fetchedDataN:(UIViewController *)response
{
if ([controller isKindOfClass:[ViewControllerSubclass class]])
{
//The controller is a ViewControllerSubclass or a subclass of ViewControllerSubclass your code here
}
if ([controller isKindOfClass:[MyViewControllerSubclass class]])
{
//The controller is a MyViewControllerSubclass or a subclass of MyViewControllerSubclass your code here
}
}
答案 2 :(得分:0)
这取决于您是否只想传递ViewController
和/或它的后代或UIViewController
以及所有后代。 UIViewController
将更通用,因为(我假设)ViewController
是UIViewController
的子类,可能您不再扩展ViewController
。一切都取决于上下文,如果您需要使用ViewController
中定义的任何特定方法/属性,或者您只想接收任何视图控制器子类UIViewController
。
答案 3 :(得分:0)
如果你想传递一个UIViewController;使用第一种方法。 我从来没有听说过'ViewController'这个类型。它是你自己的类型?如果您总是希望确保传递的变量是'ViewController'类型,请使用第二种方法。