Advertisement
davideasyclick

ViewController

Jan 27th, 2017
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #import <UIKit/UIKit.h>
  2.  
  3. @interface ViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
  4.  
  5. @property (weak, nonatomic) UITableView *tableView;
  6. @property (weak, nonatomic) UIButton *actionButton;
  7.  
  8. @end
  9.  
  10.  
  11.  
  12. //
  13. //  ViewController.m
  14. //  Teste
  15. //
  16. //  Created by teste teste on 27/01/17.
  17. //  Copyright © 2017 shipnow. All rights reserved.
  18. //
  19.  
  20. #import "ViewController.h"
  21.  
  22. @interface ViewController ()
  23.  
  24. @end
  25.  
  26. @implementation ViewController
  27.  
  28. -(void)loadView {
  29.     [super loadView];
  30.    
  31.     UITableView *table = [[UITableView alloc] init];
  32.     [self.view addSubview:table];
  33.     self.tableView = table;
  34.    
  35.     UIButton *actionButton = [[UIButton alloc] init];
  36.     actionButton.backgroundColor=[UIColor blueColor];
  37.     [actionButton setTitle:@"Test" forState:UIControlStateNormal];
  38.     [self.view addSubview:actionButton];
  39.     self.actionButton = actionButton;
  40. }
  41.  
  42. -(void)viewDidLoad {
  43.     [super viewDidLoad];
  44.    
  45.     [self setupTableViewDataSource];
  46.     [self setupConstraints];
  47. }
  48.  
  49. -(void)setupTableViewDataSource{
  50.     [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"normalCell"];
  51.    
  52.     _tableView.dataSource = self;
  53.     _tableView.delegate = self;
  54. }
  55.  
  56. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  57.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"normalCell"];
  58.    
  59.     cell.textLabel.text=[NSString stringWithFormat:@"Test %d", indexPath.row];
  60.    
  61.     return cell;
  62. }
  63.  
  64. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  65.     return 40;
  66. }
  67.  
  68. -(void)setupConstraints {
  69.     [_tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
  70.     [_actionButton setTranslatesAutoresizingMaskIntoConstraints:NO];
  71.    
  72.     NSDictionary *metrics = @{@"buttonHeight":@30};
  73.     NSDictionary *views = NSDictionaryOfVariableBindings(_tableView, _actionButton);
  74.    
  75.     [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_tableView]|" options:0 metrics:nil views:views]];
  76.    
  77.     [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_actionButton]|" options:0 metrics:nil views:views]];
  78.    
  79.     [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_tableView][_actionButton(==buttonHeight)]|" options:0 metrics:metrics views:views]];
  80. }
  81.  
  82.  
  83. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement