2012-09-11 51 views
0

我想从UIAlertView模式到视图控制器。不能从UIAlertView更改viewcontroller

- (IBAction)cancelScripting:(id)sender { 


UIAlertView *areYouSure = [[UIAlertView alloc]initWithTitle:@"Are You Sure?" message:@"Are you sure you want to quit scripting?" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 

[areYouSure show]; 



} 


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 

if (buttonIndex == 1) { 


    CRHViewController *firstView = [[CRHViewController alloc] init]; 


    [self.navigationController modalViewController:firstView animated:YES]; } 
} 

在我.h文件中我有一个UINavigatoinDelegate设置

@interface CRHScripting : UIViewController  <UITextViewDelegate,UINavigationControllerDelegate> 

在故事板,我有我的视图控制器的标识设置的firstView。

线

[self.navigationController modalViewController:firstView animated:YES]; 

是给我的一切烦恼。错误说

"No visible @interface for 'UINavigationController' declares the selector  'modalViewController:animated:' 

这是什么意思?

更新:现在我查看wont't完全加载,但它会显示视图控制器

这里是我的初始化代码:

#import "CRHViewController.h" 

@interface CRHViewController() 

@end 

@implementation CRHViewController 


-(void)updateTimer { 

NSDateFormatter *format = [[NSDateFormatter alloc]init]; 

[format setDateFormat:@"h:mm"]; 
clockLabel.text = [format stringFromDate:[NSDate date]]; 

} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 




    // Do any additional setup after loading the view, typically from a nib. 

    timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self  selector:@selector(updateTimer) userInfo:nil repeats:YES]; 

    [homeIconScrollView setScrollEnabled:YES]; 
    [homeIconScrollView setContentSize:CGSizeMake (150,1100)]; 

    NSLog(@"Did Load first View"); 

} 

- (void)viewDidAppear:(BOOL)animated { 



[UIImageView beginAnimations:NULL context:nil]; 
[UIImageView setAnimationDuration:2]; 
[scrollNotify setAlpha:0]; 
[UIImageView commitAnimations]; 


} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 
{ 
return (interfaceOrientation == UIDeviceOrientationLandscapeRight); 
} 

@end 

回答

1

- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion是一个UIViewController方法不是一个UINavigationController方法。正确的路线是:

[self presentViewController:firstView animated:YES completion:nil]; 

*注意- (void)presentModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated现在显示被废弃。如果你仍然想使用它:

[self presentModalViewController:firstView animated:YES]; 
+0

工作,但是当它模式化到视图控制器它会出现黑暗,我不能做任何事情。就像它没有启用或什么的。 – Craig

+0

您的新视图控制器加载是否成功?你可以在viewDidLoad中验证它吗? – ohr

+0

未成功加载。 – Craig

1

你有一个错字:它的presentModalViewController

它抛出错误,因为它无法找到具有该名称的方法,你拼错

+0

它摆脱了错误,但现在按钮什么都不做。我把一个nslog和按钮工作,但它不会呈现控制器。 – Craig

+0

尝试使用'didDismissWithButtonAtIndex'而不是'clickedButtonAtIndex' – jere