0

私はiPhoneアプリケーションで作業しています.XCode 4.3.2ツールを使用してアプリケーションを開発しています(ストーリーボードは使用していません)。ボタンを押しhomescreen.mてログイン画面に移動すると、アプリを実行すると、ホームからログイン画面に移動できません。この問題を解決するにはどうすればよいですか?
私はこれを試しました:

クラス名 -Appdelegate.m

     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    home = [[HomeScreen alloc]init];
    UINavigationController *navi =[[UINavigationController alloc]initWithRootViewController:home];
    [self.window addSubview:navi.view];
    return YES;
}

クラス名 - HomeScreen.m

#import "HomeScreen.h"
#import "LoginScreen.h"

@interface HomeScreen ()

@end

@implementation HomeScreen

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"HomeScreen";

    UIButton *Button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    Button1.frame = CGRectMake(10, 100, 100, 50);
    [Button1 setTitle:@"Homescreen" forState:UIControlStateNormal];
    [Button1 addTarget:self action:@selector(GotONext) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:Button1]; 
    // Do any additional setup after loading the view.
}


-(void)GotONext
{
    LoginScreen *log =[[LoginScreen alloc]init];
    [self.navigationController pushViewController:log animated:YES];
}

クラス名 - LoginScreen.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title=@"LoginScreen";


}

ここに画像の説明を入力

4

2 に答える 2

1

以下のコードを試してください...

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
home = [[[HomeScreen alloc] initWithNibName:@"HomeScreen" bundle:nil] autorelease];
        UINavigationController *navviewController1=[[UINavigationController alloc]initWithRootViewController: HomeScreen];
self.window.rootViewController = navviewController1;
    return YES;
}

次のボタンメソッドでは、次のコードを使用します...

-(void)GotONext
{
    LoginScreen *log =[[LoginScreen alloc]initWithNibName:@"LoginScreen" bundle:nil] autorelease];
    [self.navigationController pushViewController:log animated:YES];
}

これがお役に立てば幸いです...

:)

于 2012-09-17T07:40:59.840 に答える
0

initwithNibName:@"LogonScreen" と書くのを忘れていると思います。

-(void)GotONext
{
    LoginScreen *log =[[LoginScreen alloc] initWithNibName:@"LoginScreen" bundle:nil];
    [self.navigationController pushViewController:log animated:YES];
}
于 2012-09-17T08:42:05.827 に答える