0

我正在尝试从 UIAlertView 模态到视图控制器。

- (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:' 

这是什么意思?

更新:现在我的视图不会完全加载,但它会显示视图控制器

这是我的初始化代码:

#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
4

2 回答 2

1

你有一个错字:它的presentModalViewController.

它会引发该错误,因为它找不到您拼写错误的名称的方法

于 2012-09-11T23:37:08.497 回答
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];
于 2012-09-12T00:11:18.117 回答