【发布时间】:2013-12-26 13:52:36
【问题描述】:
我的问题
我在 UINavigationController 中使用 UITabBarController。 UITabBarController 内部有三个 tableview。如图所示,第一个表格视图正确显示,而其他两个表格视图部分隐藏在导航栏后面。我该如何解决这个问题?
我的层次结构:
- 根目录:UINavigationController
- UITabBar 控制器
- UITableViewController (table1,table2,table3)
- UITabBar 控制器
这是我的代码:
AppDelegate.m
#import "AppDelegate.h"
#import "TableViewController.h"
@interface AppDelegate()
@property UINavigationController* nav;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
TableViewController* table1 = [[TableViewController alloc]init];
TableViewController* table2 = [[TableViewController alloc]init];
TableViewController* table3 = [[TableViewController alloc]init];
table1.title = @"table1";
table2.title = @"table2";
table3.title = @"table3";
UITabBarController* t = [[UITabBarController alloc] init];
[t setViewControllers:@[table1,table2,table3]];
self.nav = [[UINavigationController alloc] initWithRootViewController:t];
[self.window setRootViewController:self.nav];
[self.window makeKeyAndVisible];
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application{}
- (void)applicationDidEnterBackground:(UIApplication *)application{}
- (void)applicationWillEnterForeground:(UIApplication *)application{}
- (void)applicationDidBecomeActive:(UIApplication *)application{}
- (void)applicationWillTerminate:(UIApplication *)application{}
@end
TableViewController.m
#import "TableViewController.h"
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style{
self = [super initWithStyle:style];
if (self) {}
return self;
}
- (void)viewDidLoad{
[super viewDidLoad];
[self.tabBarController.view layoutSubviews];
}
- (void)didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell* c = [[UITableViewCell alloc] init];
[c.textLabel setText:[NSString stringWithFormat:@"%d", indexPath.row]];
return c;
}
@end
【问题讨论】:
-
您是否尝试设置 self.tableView.contentInset = UIEdgeInsetsMake(64.0f, 0.0, 0.0, 0.0);?在你的 UITableviewControllers 中
-
self.tableView.contentInset = UIEdgeInsetsMake(64.0f, 0.0, 0.0, 0.0);将使 table2 和 table3 看起来不错,但也会使 table1 降低 64 点。
-
@১২৩:谢谢它有效。顺便说一句,你的名字是什么语言?
-
我迟到了,但是......遇到同样问题的任何人都应该取消选中自动调整滚动视图插图......从属性检查器中可以解决问题
标签: ios objective-c uitableview uinavigationcontroller uitabbarcontroller