问题:标签栏控制器 +导航控制器:以编程方式

发布于 2024-12-06 08:53:23 字数 2397 浏览 0 评论 0原文

大家好,

我正在尝试制作一个带有标签栏控制器和导航控制器的应用程序。 但我遇到了一些问题...当我尝试在第二个视图上 popViewController 时,应用程序崩溃了。 有人知道发生了什么事吗?

我的代表:

// -- PranchetaAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    self.tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:1];

    PlayersViewController* playersViewController = [[PlayersViewController alloc] initWithTabBar];

    self.navigationController = [[UINavigationController alloc] initWithRootViewController:playersViewController];

    [localControllersArray addObject:self.navigationController];

    [self.navigationController release];

    self.tabBarController.viewControllers = localControllersArray;
    [self.window addSubview:self.tabBarController.view];

    [self.window makeKeyAndVisible];

    [self.navigationController release];
    [localControllersArray release];

    return YES;

}

我的第一个视图:

// -- PlayersViewsController.m

- (id)initWithTabBar {

    if (self)
    {

        self.title = @"Players";
        self.tabBarItem.image = [UIImage imageNamed:@"PlayersTabBarIcon.png"];

        CustomNavigationBarButton *addButtonView = [[CustomNavigationBarButton alloc] initWithImage:@"AddButton.png" withSelected:@"AddButtonSelected.png"];

        [addButtonView addTarget:self action:@selector(gotoCreatePlayers) forControlEvents:UIControlEventTouchUpInside];

        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:addButtonView];

        self.navigationItem.rightBarButtonItem = addButton;

        [addButton release];
        [addButtonView release];

    }

    return self;

}

- (void)gotoCreatePlayers {

    CreatePlayersViewController *createPlayer = [CreatePlayersViewController new];
    [self.navigationController pushViewController:createPlayer animated:YES];
    [createPlayer release];

}

当我推动第二个视图时,我尝试返回导航。但是应用程序崩溃了...

指定错误:

// --  main.m
int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

谢谢大家!

Hello guys,

I trying to make a app with tabbar controller and navigation controller.
But i get some problems... When i try to popViewController on my second view, the app crash.
Some one knows what's going on?

My Delegate:

// -- PranchetaAppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    self.tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:1];

    PlayersViewController* playersViewController = [[PlayersViewController alloc] initWithTabBar];

    self.navigationController = [[UINavigationController alloc] initWithRootViewController:playersViewController];

    [localControllersArray addObject:self.navigationController];

    [self.navigationController release];

    self.tabBarController.viewControllers = localControllersArray;
    [self.window addSubview:self.tabBarController.view];

    [self.window makeKeyAndVisible];

    [self.navigationController release];
    [localControllersArray release];

    return YES;

}

My First View:

// -- PlayersViewsController.m

- (id)initWithTabBar {

    if (self)
    {

        self.title = @"Players";
        self.tabBarItem.image = [UIImage imageNamed:@"PlayersTabBarIcon.png"];

        CustomNavigationBarButton *addButtonView = [[CustomNavigationBarButton alloc] initWithImage:@"AddButton.png" withSelected:@"AddButtonSelected.png"];

        [addButtonView addTarget:self action:@selector(gotoCreatePlayers) forControlEvents:UIControlEventTouchUpInside];

        UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithCustomView:addButtonView];

        self.navigationItem.rightBarButtonItem = addButton;

        [addButton release];
        [addButtonView release];

    }

    return self;

}

- (void)gotoCreatePlayers {

    CreatePlayersViewController *createPlayer = [CreatePlayersViewController new];
    [self.navigationController pushViewController:createPlayer animated:YES];
    [createPlayer release];

}

When i push my second view, i try to go back into the navigation. But the app crash...

Error appointed:

// --  main.m
int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

Thanks guys!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花桑 2024-12-13 08:53:23

尝试这个:

将:更改

CreatePlayersViewController *createPlayer = [CreatePlayersViewController new];

为:

CreatePlayersViewController *createPlayer = [CreatePlayersViewController alloc];

如果还有任何要调用的初始化方法,那么它应该看起来像这样

CreatePlayersViewController *createPlayer = [[CreatePlayersViewController alloc]init];

尝试这样的事情:
将其添加到 .h 文件中:CreatePlayersViewController *createPlayer
然后将上面的代码替换为:

if (createPlayer ==nil) {
    CreatePlayersViewController *nextView = [[CreatePlayersViewController alloc] initWithStyle:UITableViewStylePlain];
    self.createPlayer = nextView;
    [nextView release];
}
self.meetTheTeam.view.hidden = NO;


[self.navigationController pushViewController:self.meetTheTeam animated:YES];

try this:

change:

CreatePlayersViewController *createPlayer = [CreatePlayersViewController new];

to:

CreatePlayersViewController *createPlayer = [CreatePlayersViewController alloc];

also if there are any init methods to call than it should look like this

CreatePlayersViewController *createPlayer = [[CreatePlayersViewController alloc]init];

try somthing like this:
ADD THIS TO THE .h FILE: CreatePlayersViewController *createPlayer
then replace your code above with this:

if (createPlayer ==nil) {
    CreatePlayersViewController *nextView = [[CreatePlayersViewController alloc] initWithStyle:UITableViewStylePlain];
    self.createPlayer = nextView;
    [nextView release];
}
self.meetTheTeam.view.hidden = NO;


[self.navigationController pushViewController:self.meetTheTeam animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文