Приложение iOS вылетает при открытии при переключении видов вращения - PullRequest
2 голосов
/ 22 января 2011

Я пытаюсь разработать приложение в XCode, которое переключится на новый вид после поворота.

Вот код для view1controller.h:

#import UIKit/UIKit.h

@interface TestViewController : UIViewController {}

IBOutlet UIView *portrait;
IBOutlet UIView *landscape;

@property(nonatomic,retain) UIView *portrait;
@property(nonatomic,retain) UIView *landscape;

@end

и вот код для view1controller.m:

#import "view1controller.h"

@implementation TestViewController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)))
    {
        self.view = landscape;  
    } else if (((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))) {
        self.view = portrait;
    }

    return YES;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
    [super dealloc];
}

@synthesize portrait,landscape;

@end

В любом случае, приложение открывается, но при открытии вылетает.

Ответы [ 3 ]

1 голос
/ 22 января 2011

Ваши скобки в заголовке неуместны.

@interface TestViewController : UIViewController {

    IBOutlet UIView *portrait;
    IBOutlet UIView *landscape;

}

@property(nonatomic,retain) UIView *portrait;
@property(nonatomic,retain) UIView *landscape;

@end

Кроме того, @synthesize portrait,landscape; необходимо перейти под @implementation TestViewController

@implementation TestViewController
@synthesize portrait,landscape;

Обратите внимание на UIView на этом изображении: alt text

1 голос
/ 22 января 2011

Попробуйте что-то вроде:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.view = landscapeleft;  
    } 

    if (interfaceOrientation == UIInterfaceOrientationPortrait) 
    {
        self.view = portrait;
    }

    if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        self.view = portraitupsidedown;
    }

    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        self.view = landscapeleft;
    }


    return YES;
}
0 голосов
/ 22 января 2011

Я бы сделал следующее:

if(((interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationLandscapeRight)))
{
    [portrait removeFromSuperview];
    [self.view addSubview:landscape];
} else if (((interfaceOrientation == UIInterfaceOrientationPortrait) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown))) {
    [landscape removeFromSuperview];
    [self.view addSubview:portrait];
}

Надеюсь, это поможет!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...