iphone - 标签栏应用中的表格 View

标签 iphone ios xcode tableview tabbar

我已经找了几个星期了,但没有找到 Xcode 4 的教程,展示了如何将表格 View 添加到选项卡栏应用程序。我想知道您是否可以指出正确的方向?

谢谢

最佳答案

任何 TabBarController 教程都应该这样做,因为您将 UIViewControllers 添加到选项卡栏。对于 TableView ,只需创建一个 UITableViewController。您应该能够将其添加到选项卡栏 Controller ......或任何其他 View Controller 。例如,如果您发现其他一些教程使用导航 Controller 执行 TabBar ... 只需将教程的导航 Controller 部分替换为 UITableViewController。还有大量关于 UItableViewControllers 的文档和教程。

例如,如果您在应用委托(delegate) 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;

然后在您添加到标签栏的每个 View Controller 中,确保在它们的初始化中将标签栏项目添加到它们

- (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;
}

关于iphone - 标签栏应用中的表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7700747/

相关文章:

ios - 在 iPad Pro 上放大的 iPad Air App

objective-c - 当 PFFile 太大时应用程序崩溃

iphone - 警告 : the current language does not match this frame

ios - 基于调试级别的 Swift NSLog 启用

xcode - Mac App Store无效签名问题

ios - PopoverPresentation Controller 未以左上箭头方向显示在屏幕中央

ios - 当前台应用程序收到推送通知时刷新当前 View ?

ios - 透明的 iOS 导航栏

iphone - ios如何查看是否有来自Urban Airship的通知?

iphone - UITable 为我的最后一行 UITableViewCell 加载第一个 UITableViewCell