Iphone UiButton/iAction-在情节提要中从根视图链接到主视图
我尝试调用故事板上的主Iphone UiButton/iAction-在情节提要中从根视图链接到主视图,iphone,ios5,storyboard,ibaction,Iphone,Ios5,Storyboard,Ibaction,我尝试调用故事板上的主ViewController。在我的应用程序中,还有一个附加的.h,.m文件,没有xib或故事板 在这个.m文件中,T包含一个按钮: UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; [button addTarget:self action:@selector(home:)forControlEvents:UIControlEventTouchDown]; [button setTi
ViewController
。在我的应用程序中,还有一个附加的.h
,.m
文件,没有xib或故事板
在这个.m文件中,T包含一个按钮:
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(home:)forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];
NSLog(@"Home-Button line 645");
此按钮应链接到情节提要中的主ViewController。该视图具有标识符菜单。我没有收到错误,但是视图没有更改为我的主ViewController。怎么了
- (IBAction)home:(id)sender {
NSLog(@"Button was tapped");
ViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"HauptMenu"];
NSLog(@"1");
[viewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
NSLog(@"2");
[self.navigationController pushViewController:viewController animated:NO];
[viewController release];
NSLog(@"3");
}
如果您的
.m
文件未与任何情节提要关联,那么self.storyboard
不是Nil
尝试:
确保将名为:的故事板更改为故事板的名称
您可能没有收到任何错误,因为Objective-C处理nil的方式与其他语言不同,它(通常)不会抛出异常。如果您尝试对nil调用方法,它只会返回nil。以下代码将愉快地运行,不会引发编译器或运行时错误:
UIViewController * test = nil;
[test viewDidLoad];
如果您的
.m
文件未与任何情节提要关联,那么self.storyboard
不是Nil
尝试:
确保将名为:的故事板更改为故事板的名称
您可能没有收到任何错误,因为Objective-C处理nil的方式与其他语言不同,它(通常)不会抛出异常。如果您尝试对nil调用方法,它只会返回nil。以下代码将愉快地运行,不会引发编译器或运行时错误:
UIViewController * test = nil;
[test viewDidLoad];
我自己也有这个问题。多亏了这个答案,现在它工作了 这是我的代码,希望其他人可以使用:
// Declare the storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
// Declare the next view controller
NextViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:@"NextViewController"];
// Pass value
nextViewController.result = result;
[currentObject memberfunction:value];
// Define transition
nextViewController.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
// Perform change
[self presentModalViewController:nextViewController animated:YES];
我自己也有这个问题。多亏了这个答案,现在它工作了 这是我的代码,希望其他人可以使用:
// Declare the storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]];
// Declare the next view controller
NextViewController *nextViewController = [storyboard instantiateViewControllerWithIdentifier:@"NextViewController"];
// Pass value
nextViewController.result = result;
[currentObject memberfunction:value];
// Define transition
nextViewController.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
// Perform change
[self presentModalViewController:nextViewController animated:YES];
但还有一个问题;-)我使用MainstryBoard_iphone和MainstryBoard_ipad。我只想使用一个.h和.m文件。是否可以切换,或者如何切换?可以使用NSString*storyboard=[[NSBundle mainBundle].infoDictionary objectForKey:@“UIMainstryBoardFile]”查找主情节提要;但还有一个问题;-)我使用MainstryBoard_iphone和MainstryBoard_ipad。我只想使用一个.h和.m文件。是否可以切换,或者如何切换?可以使用NSString*storyboard=[[NSBundle mainBundle].infoDictionary objectForKey:@“UIMainstryBoardFile]”查找主情节提要;