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 回答