2014-09-12 116 views
0

首先要注意的是,我不使用xib或故事板,因此一切都需要以编程方式完成。如何在表格视图中将静态视图添加到屏幕底部?

我有一个UITableView,我太需要一个自定义静态视图添加到屏幕底部时,表视图是开放的(它会作为一个工具栏的功能)。我不能将它作为tableview的直接子视图添加,因为它随后会与表一起滚动。另外值得一提的是,所有这些都位于UINavigationController之内。

任何人都知道我可以解决这个问题吗?

+1

的UINavigationController - >的UIViewController - >的UITableView和UIView的(底栏) – 2014-09-12 16:27:00

+0

你是怎么为你的控制器使用,你继承一个UIViewController还是你使用一个UITableViewController? – Waruna 2014-09-12 17:28:34

回答

0

您可以添加UIToolbar到屏幕的底部,UIBarButtonItems并添加UITableView与高度相等的表视图控制器的顶部查看高度 - 工具栏的高度。

+0

为了将它放在表格视图下,我需要添加我的子视图? – 2014-09-12 16:31:50

0

这里是一个实现子类的UIViewController,并添加UITableView中和的UITabBarController它。

@interface RKViewController()<UITableViewDataSource, UITableViewDelegate> 

@property (nonatomic, strong) UITableView *tableView; 
@property (nonatomic, strong) UITabBar *tabBar; 
@property (nonatomic, strong) UITabBarController *tabBarController; 

@end 

@implementation RKViewController 

-(id)init 
{ 
    self = [super init]; 
    if (self) { 

     self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 500)]; 
     self.tableView.dataSource = self; 
     self.tableView.delegate = self; 

     self.tabBarController = [[UITabBarController alloc] init]; 

    } 
    return self; 
} 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.view.backgroundColor = [UIColor redColor]; 

    UIViewController *vc1 = [[UIViewController alloc] init]; 
    vc1.tabBarItem.title = @"Item 1"; 
    UIViewController *vc2 = [[UIViewController alloc] init]; 
    vc2.tabBarItem.title = @"Item 2"; 

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:vc1,vc2, nil]; 

    [self.view addSubview:self.tableView]; 
    [self.view addSubview:self.tabBarController.view]; 
} 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return 10; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return [UITableViewCell new]; 
} 
- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 
@end 
相关问题