Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <UIKit/UIKit.h>
- @interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
- @property (weak, nonatomic) UITableView *tableView;
- @property (weak, nonatomic) UIButton *actionButton;
- @end
- //
- // ViewController.m
- // Teste
- //
- // Created by teste teste on 27/01/17.
- // Copyright © 2017 shipnow. All rights reserved.
- //
- #import "ViewController.h"
- @interface ViewController ()
- @end
- @implementation ViewController
- -(void)loadView {
- [super loadView];
- UITableView *table = [[UITableView alloc] init];
- [self.view addSubview:table];
- self.tableView = table;
- UIButton *actionButton = [[UIButton alloc] init];
- actionButton.backgroundColor=[UIColor blueColor];
- [actionButton setTitle:@"Test" forState:UIControlStateNormal];
- [self.view addSubview:actionButton];
- self.actionButton = actionButton;
- }
- -(void)viewDidLoad {
- [super viewDidLoad];
- [self setupTableViewDataSource];
- [self setupConstraints];
- }
- -(void)setupTableViewDataSource{
- [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"normalCell"];
- _tableView.dataSource = self;
- _tableView.delegate = self;
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"normalCell"];
- cell.textLabel.text=[NSString stringWithFormat:@"Test %d", indexPath.row];
- return cell;
- }
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 40;
- }
- -(void)setupConstraints {
- [_tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
- [_actionButton setTranslatesAutoresizingMaskIntoConstraints:NO];
- NSDictionary *metrics = @{@"buttonHeight":@30};
- NSDictionary *views = NSDictionaryOfVariableBindings(_tableView, _actionButton);
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_tableView]|" options:0 metrics:nil views:views]];
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_actionButton]|" options:0 metrics:nil views:views]];
- [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_tableView][_actionButton(==buttonHeight)]|" options:0 metrics:metrics views:views]];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement