2014-09-12 114 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 
相關問題