2012-09-11 48 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