I have added a UIBarButtonItem in the main screen and created a b.xib, bh and bm files for it. when i click on the button it should open the respected screen but it doesn't and opens blank screen.
I am very new to iOS programming....
below is the code in Am
file where I added button and when click on it it should open 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];
}
any idea...how can i make it work perfectly...
BViewController *b = [[BViewController alloc] init];
如果为ViewController创建一个笔尖,则应改用initWithNibName:bundle:
Try this:
XIBs
BViewController *bViewController = [[BViewController alloc] initWithNibName:@"Myview" bundle:nil];
[self.view.window.rootViewController presentViewController: bViewController
animated: YES
completion: nil];
Storyboard
// 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];
Hope this will help.
Note: Try to give some meaningful names to your view controllers rather using AViewController and BViewController
you have to specify your nib name while presenting view like this
BViewController *b = [[BViewController alloc] initWithNibName:@"your_nib_name" bundle:nil];
[self presentModalViewController:b animated:YES];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.