2012-12-14 53 views
0

我有以下代碼:黑屏更改視圖4,5

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

如果你正在使用'storyboard',爲什麼你需要給'initWithNibName'。你可以從'MapViewController'鏈接到你的'storyboard'中的'PlaceViewController' – arthankamal

回答

0

,如果你使用的是故事板...進入故事板編輯器,並在屬性檢查器中,設置一個標識符,讓說「PlaceMap」(圖中「AddPlayer」)

enter image description here

變化您的代碼:

- (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]; 
} 

您可以阿洛斯檢查,一個非常好的教程: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]; 
+0

這不起作用,因爲我沒有使用storyboard,並且該按鈕位於MkMapView的註釋中:「UIButton * rightButton = [UIButton buttonWithType: UIButtonTypeDetailDisclosure]; [rightButton setTitle:annotation.title forState:UIControlStateNormal]; [pinView setRightCalloutAccessoryView:rightButton];「 – Xose

+0

我播下了你的評論:「和故事板: http://img685.imageshack.us/img685/1233/screengy.png」 – TonyMkenu

+0

對不起,我只用於故事板設計視圖,而不是按鈕 – Xose