我有以下代码:
MapViewController.h
#import <UIKit/UIKit.h>
#import "PlaceViewController.h"
@interface MapViewController : UIViewController <MKMapViewDelegate> {
IBOutlet PlaceViewController *placeview;
}
- (IBAction)passPlace:(id)sender;
MapViewController.m
@synthesize placeview;
- (IBAction)passPlace:(id)sender{
self.placeview = [[[PlaceViewController alloc] initWithNibName:nil bundle:nil] autorelease];
[self presentViewController:placeview animated:YES completion:nil];
}
PlaceViewController.h
@interface PlaceViewController : UIViewController{
}
- (IBAction)back:(id)sender;
@end
PlaceViewController.m
@implementation PlaceViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
NSLog(@"Change!!!!!");
[super viewDidLoad];
// Do any additional setup after loading the view.
}
故事板:
http://img685.imageshack.us/img685/1233/screengy.png
我不知道我做错了什么,因为当我更改视图时,PlaceViewController是一个带有蓝色状态栏的黑屏。
任何人都可以帮助我吗?感谢
答案 0 :(得分:0)
如果你正在使用故事板...进入故事板编辑器和属性检查器,设置一个标识符,比如说“PlaceMap”(图片“AddPlayer”)
更改您的代码:
- (IBAction)passPlace:(id)sender{
self.placeview = [[[PlaceViewController alloc] initWithNibName:nil bundle:nil] autorelease];
[self presentViewController:placeview animated:YES completion:nil];
}
与
- (IBAction)passPlace:(id)sender{
PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"PlaceMap"];
[self.navigationController pushViewController:newView animated:YES];
}
你可以查看alos,一个非常好的教程:http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1
<强> UPD 强>
用于导航控制器
[self presentViewController:placeview animated:YES completion:nil];
如果你想要模态...你可以使用:
newView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//deprecated 6.0
// [self presentModalViewController:newView animated:YES];
//from 5.0
[self presentViewController:newView animated:YES completion:NULL];