标签栏应用程序中的表格视图

发布于 2024-12-08 17:58:40 字数 85 浏览 0 评论 0原文

我已经找了好几个星期了,但没有找到 Xcode 4 的教程,展示如何将表视图添加到选项卡栏应用程序。我想知道你能否为我指明正确的方向?

谢谢

I have been looking for weeks now and had no luck trying to find a tutorial for Xcode 4 showing how to add a Table View to a Tab Bar app. I was wondering if you could point me in the right direction?

Thanks

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

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

发布评论

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

评论(1

原谅过去的我 2024-12-15 17:58:40

任何 TabBarController 教程都应该这样做,因为您将 UIViewController 添加到选项卡栏。对于表视图,只需创建一个 UITableViewController 即可。您应该能够将其添加到选项卡栏控制器...或任何其他视图控制器。例如,如果您发现其他一些教程使用 navigationController 来实现 TabBar ...只需将教程中的 navigationController 部分替换为 UITableViewController 即可。还有大量关于 UItableViewControllers 的文档和教程。

例如,如果您在应用程序委托 didfinishLaunchingWithOptions 中查看此代码。在此之前,创建了 MyTableViewController (UITableViewController) 和其他一些 UIViewController。

// View Controllers for tabController - could be UItableViewControllers or any
// other UIViewController.  You will add this to the tabController
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];

MyTableViewController *myTable = [[MyTableViewController alloc] initWithNibName:@"MyTableViewController" bundle:nil];
[viewControllers addObject:myTable];

SomeOtherUIViewController *other = [[SomeOtherUIViewController alloc] initWithNibName:@"SomeOtherUIViewController" bundle:nil];
[viewControllers addObject:other];    

// add the UIViewControllers to the tabController
[tabController setViewControllers:viewControllers];

// add tabbar and show
[[self window] addSubview:[tabController view]];
[self.window makeKeyAndVisible];
return YES;

然后在添加到选项卡栏中的每个视图控制器中,确保在其 init 中将选项卡栏项添加到它们中

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        UITabBarItem *barItem = [[UITabBarItem alloc] 
                             initWithTitle:@"Progress" 
                             image:[UIImage imageNamed:@"report.png"] tag:2];

        [self setTabBarItem:barItem];
        [barItem release];
    }
    return self;
}

Any TabBarController tutorial should do because you add UIViewControllers to the tab bar. For the table view, simply create a UITableViewController. You should be able to add that to the tab bar controller ... or any other view controller. For example, if you find some other tutorial doing a TabBar with a navigationController ... simply replace the navigationController part of the tutorial with a UITableViewController. There's also plenty of docs and tutorials on UItableViewControllers.

For example, if you look at this code in an app delegate didfinishLaunchingWithOptions. Pior to this, a MyTableViewController was created (UITableViewController) and some other UIViewController.

// View Controllers for tabController - could be UItableViewControllers or any
// other UIViewController.  You will add this to the tabController
NSMutableArray *viewControllers = [[NSMutableArray alloc] init];

MyTableViewController *myTable = [[MyTableViewController alloc] initWithNibName:@"MyTableViewController" bundle:nil];
[viewControllers addObject:myTable];

SomeOtherUIViewController *other = [[SomeOtherUIViewController alloc] initWithNibName:@"SomeOtherUIViewController" bundle:nil];
[viewControllers addObject:other];    

// add the UIViewControllers to the tabController
[tabController setViewControllers:viewControllers];

// add tabbar and show
[[self window] addSubview:[tabController view]];
[self.window makeKeyAndVisible];
return YES;

And then in each of those view controllers that you added to the tabbar, make sure you add the tabbar item to them in their init

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) 
    {
        UITabBarItem *barItem = [[UITabBarItem alloc] 
                             initWithTitle:@"Progress" 
                             image:[UIImage imageNamed:@"report.png"] tag:2];

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