我正在尝试从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>
在storyboard中,我将视图控制器的标识符设置为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
答案 0 :(得分:1)
你有一个拼写错误:presentModalViewController
。
它会抛出该错误,因为它无法找到您拼写错误名称的方法
答案 1 :(得分: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];