UITabBarController 的多个视图
我正在尝试构建一个应用程序,其中有一个包含 4 个条目的 TabBarController。 当我选择第一个条目时,会显示一个带有 UITableView 的视图。 该 TableView 充满了多个条目。
我想做的是: 当选择 UITableView 中的一个条目时,应该会显示另一个视图;详细视图。
.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
if(self.secondView == nil) {
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
self.secondView = secondViewController;
[secondViewController release];
}
// Setup the animation
[self.navigationController pushViewController:self.secondView animated:YES];
}
}
.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface FirstViewController : UIViewController {
SecondViewController *secondView;
NSMutableArray *myData;
}
@property (nonatomic, retain) SecondViewController *secondView;
@property (nonatomic, copy, readwrite) NSMutableArray* myData;
@end
这是我到目前为止所拥有的。
不幸的是..代码运行,但第二个视图没有显示。
I'm trying to build an app where I have a TabBarController with 4 entries.
When I select the first entry, a view with a UITableView shows up.
This TableView is filled with several entries.
What I would like to do is:
When an entry out of that UITableView gets selected, another view should show up; a detailview.
.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
if(self.secondView == nil) {
SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
self.secondView = secondViewController;
[secondViewController release];
}
// Setup the animation
[self.navigationController pushViewController:self.secondView animated:YES];
}
}
.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface FirstViewController : UIViewController {
SecondViewController *secondView;
NSMutableArray *myData;
}
@property (nonatomic, retain) SecondViewController *secondView;
@property (nonatomic, copy, readwrite) NSMutableArray* myData;
@end
This is what I have so far.
Unfortunately.. the code runs, bit the second view does not show up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的第一个视图控制器是否包含在 UINavigationController 中?当您设置
UITabBarController
时,您应该添加UINavigationControllers而不是UIViewController子类,例如:此外,根据您的代码,您不需要将secondViewController保留为ivar,因为UINavigationController会自动保留它的视图控制器(当你不显示它时保留它会消耗不必要的内存)。
Is your first view controller wrapped in a
UINavigationController
? When you set up yourUITabBarController
, you should add UINavigationControllers rather than your UIViewController subclasses, e.g.:Also, based on your code, you don't need to keep your secondViewController as an ivar, since UINavigationController automatically retains its view controllers (and retaining it when you're not displaying it will use up unnecessary memory).