我在主屏幕中添加了一个UIBarButtonItem,并为其创建了 b.xib,b.h和b.m 文件。当我点击按钮时,它应该打开尊重的屏幕,但它不会打开并打开空白屏幕。
我是iOS编程的新手....
下面是A.m
文件中的代码,我在其中添加了按钮,点击它时应该会打开b.xib
。
UIBarButtonItem *bButton = [[UIBarButtonItem alloc]
initWithTitle:@"B"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(openB:)];
self.navigationItem.leftBarButtonItem = bButton;
bButton.TintColor = [UIColor colorWithRed:0.0 green:0.31 blue:0.56 alpha:1.0];
[bButton release];
- (void)openB:(id)sender {
BViewController *b = [[BViewController alloc] init];
// ttod.defViewC = self; //Bookmarks from the definition view
[self presentModalViewController:b animated:YES];
[b release];
}
任何想法......我怎样才能让它完美运作......
答案 0 :(得分:2)
BViewController *b = [[BViewController alloc] init];
如果为ViewController创建一个nib,则应改为使用initWithNibName:bundle:
。
答案 1 :(得分:1)
试试这个:
<强> XIBs 强>
BViewController *bViewController = [[BViewController alloc] initWithNibName:@"Myview" bundle:nil];
[self.view.window.rootViewController presentViewController: bViewController
animated: YES
completion: nil];
<强>故事板强>
// Here BViewController should be the name in storyboard scene then,
BViewController *bViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"BViewController"]
[self.view.window.rootViewController presentViewController: bViewController
animated: YES
completion: nil];
希望这会有所帮助。
注意:尝试为视图控制器提供一些有意义的名称,而不是使用 AViewController 和 BViewController
答案 2 :(得分:1)
您必须在显示此类视图时指定您的笔尖名称
BViewController *b = [[BViewController alloc] initWithNibName:@"your_nib_name" bundle:nil];
[self presentModalViewController:b animated:YES];