首页 文章

如何在表格视图中将静态视图添加到屏幕底部?

提问于
浏览
0

首先要注意的是我不使用xib或故事板,所以一切都需要以编程方式完成 .

我有一个 UITableView ,当桌面视图打开时我需要在屏幕底部添加一个自定义静态视图(它将它添加为tableview的直接子视图,因为它随表格滚动 . 另外值得一提的是所有这一切都坐在 UINavigationController 内 .

有谁知道我怎么能解决这个问题?

2 回答

  • 0

    您可以使用 UIBarButtonItemsUIToolbar 添加到屏幕底部,并将 UITableView 添加到视图控制器的顶部,高度等于表格视图高度 - 工具栏高度 .

  • 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
    

相关问题