UITableview页脚超出界限,同时以编程方式使用autolayout添加表格视图

时间:2013-11-07 17:46:18

标签: ios ios7 autolayout

以下是我的代码

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor blueColor];


    UITableView *myTableview = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    myTableview.dataSource = self;
    myTableview.delegate = self;
    myTableview.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:myTableview];

    NSLayoutConstraint* widthConstraint = [NSLayoutConstraint constraintWithItem:myTableview attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0.0];
    NSLayoutConstraint* heightConstraint = [NSLayoutConstraint constraintWithItem:myTableview attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1.0 constant:0.0];
    NSLayoutConstraint* topConstraint = [NSLayoutConstraint constraintWithItem:myTableview attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0];
    NSLayoutConstraint* leftConstraint = [NSLayoutConstraint constraintWithItem:myTableview attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];

    [self.view addConstraints:@[widthConstraint,heightConstraint,topConstraint,leftConstraint]];

    UIView* footerView = [[UIView alloc] init];
    footerView.backgroundColor = [UIColor greenColor];
    [myTableview setTableFooterView:footerView];
    footerView.frame = CGRectMake(0,0, 320, 60);


}
]

0 个答案:

没有答案