无法让辅助 UITableViewController 在 UITabBarController 内显示

发布于 2024-08-27 21:13:00 字数 1623 浏览 6 评论 0原文

我已经以编程方式创建了一个 UITabBarController ,它加载到我的应用程序委托中,如下所示:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
tabBarController = [[UITabBarController alloc] init];

myTableViewController = [[MyTableViewController alloc] init];
UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:myTableViewController] autorelease];
myTableViewController.title = @"Tab 1";
[myTableViewController release];

mySecondTableViewController = [[MySecondTableViewController alloc] init];
UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:mySecondTableViewController] autorelease];
mySecondTableViewController.title = @"Tab 2";
[mySecondTableViewController release];

tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController, table2NavController, nil]; 

[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}

现在我遇到的问题是我可以毫无问题地进入视图,但是当我尝试单击中的任何项目时表视图,我无法让辅助表视图出现在任何选项卡中。这些选项卡工作得非常好,只是次要视图。我在 myTableViewController 中使用下面的代码在选择特定行时运行(代码到达帮助行,然后崩溃)...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
    // this gets the correct view controller from a list of controllers
SecondaryViewController *svc = [self.controllers objectAtIndex:row];

    /*** HELP NEEDED WITH THIS LINE ***/    
[self.navigationController pushViewController:svc animated:YES];

}

简单地说,我试图将视图切换到新的视图控制器,同时保留选项卡可用并使用导航来回移动(就像在 iTunes 应用程序中一样)。

I've programmatically created a UITabBarController that is loaded in my App Delegate like this:

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
tabBarController = [[UITabBarController alloc] init];

myTableViewController = [[MyTableViewController alloc] init];
UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:myTableViewController] autorelease];
myTableViewController.title = @"Tab 1";
[myTableViewController release];

mySecondTableViewController = [[MySecondTableViewController alloc] init];
UINavigationController *table2NavController = [[[UINavigationController alloc] initWithRootViewController:mySecondTableViewController] autorelease];
mySecondTableViewController.title = @"Tab 2";
[mySecondTableViewController release];

tabBarController.viewControllers = [NSArray arrayWithObjects:tableNavController, table2NavController, nil]; 

[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}

Now the issue I have is that I can get into the views no problem, but when I try and click onto any item in the Table View, I can't get a secondary table view to appear in any tab. The tabs work absolutely fine, just the secondary views. I'm using the code below in my myTableViewController to run when selecting a specific row (the code reaches the HELP line, and crashes)...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
    // this gets the correct view controller from a list of controllers
SecondaryViewController *svc = [self.controllers objectAtIndex:row];

    /*** HELP NEEDED WITH THIS LINE ***/    
[self.navigationController pushViewController:svc animated:YES];

}

Simply put, I'm trying to switch views to the new view controller whilst keeping the tabs available and using the navigation to go back and forth (like in the iTunes App).

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

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

发布评论

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

评论(2

感情废物 2024-09-03 21:13:01

简而言之,我正在创建控制器数组 self.controllers,并添加对象,然后释放对象。

如果在释放数组之前不释放对象,则看起来工作没有问题。

Simply put, I was creating the controller array, self.controllers, and adding objects, and then releasing the objects.

If you do not release the object until the array is released, it appears to work no problem.

少女七分熟 2024-09-03 21:13:01

您没有在问题中包含如何初始化 self.controllers 数组。

我怀疑这个数组没有填充初始化的SecondaryViewController 对象。

编辑(添加了适用于我的代码示例):.

h 文件:

@interface FirstLevelViewController : UITableViewController {
    NSArray *controllers;
}
@property (nonatomic, retain) NSArray *controllers;
@end

和 .m 文件:

@implementation FirstLevelViewController
@synthesize controllers;
- (void)viewDidLoad {
    self.title = @"First Level";
    NSMutableArray *array = [[NSMutableArray alloc] init];

    // Disclosure Button
    DisclosureButtonController *disclosureButtonController =
    [[DisclosureButtonController alloc] 
     initWithStyle:UITableViewStylePlain];
    disclosureButtonController.title = @"Disclosure Buttons";
    disclosureButtonController.rowImage = [UIImage 
                                           imageNamed:@"disclosureButtonControllerIcon.png"];
    [array addObject:disclosureButtonController];
    [disclosureButtonController release];  

    // deleted further adds to array ...

    self.controllers = array;
    [array release];
    [super viewDidLoad];
}

You've not included in your question how you initialize the self.controllers array.

I suspect this array is not filled with initialized SecondaryViewController objects.

EDIT (Added Code example that works for me):

the .h file:

@interface FirstLevelViewController : UITableViewController {
    NSArray *controllers;
}
@property (nonatomic, retain) NSArray *controllers;
@end

and the .m file:

@implementation FirstLevelViewController
@synthesize controllers;
- (void)viewDidLoad {
    self.title = @"First Level";
    NSMutableArray *array = [[NSMutableArray alloc] init];

    // Disclosure Button
    DisclosureButtonController *disclosureButtonController =
    [[DisclosureButtonController alloc] 
     initWithStyle:UITableViewStylePlain];
    disclosureButtonController.title = @"Disclosure Buttons";
    disclosureButtonController.rowImage = [UIImage 
                                           imageNamed:@"disclosureButtonControllerIcon.png"];
    [array addObject:disclosureButtonController];
    [disclosureButtonController release];  

    // deleted further adds to array ...

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