我已经找了几个星期了,但没有找到 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/