Add buttons under a tableview

前端 未结 3 1134
感动是毒
感动是毒 2021-02-11 02:27

I\'m trying to create a view programmatically. The result that i want to have is a scroll view with a tableview inside. And under this table view i want to add some buttons

3条回答
  •  迷失自我
    2021-02-11 02:49

    Actually i found the solution. the tableview has a property named tableFooterView. All you have to do is to :

    -Create a UIView -Add a button to this view -Finaly set it on the tableFooterView

    Here is the code :

    tableView = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped];
    [tableView setDelegate:self];
    [tableView setDataSource:self];
    
    // create a UIButton (Deconnect button)
    UIButton *btnDeco = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnDeco.frame = CGRectMake(0, 0, 280, 40);
    [btnDeco setTitle:@"Déconnecter" forState:UIControlStateNormal];
    btnDeco.backgroundColor = [UIColor clearColor];
    [btnDeco setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [btnDeco addTarget:self action:@selector(deconnect:) forControlEvents:UIControlEventTouchUpInside];
    
    // create a UIButton (Change pseudo button)
    UIButton *btnChange = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    btnChange.frame = CGRectMake(0, 50, 280, 40);
    [btnChange setTitle:@"Changer Pseudo" forState:UIControlStateNormal];
    btnChange.backgroundColor = [UIColor clearColor];
    [btnChange setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    [btnChange addTarget:self action:@selector(changePseudo:) forControlEvents:UIControlEventTouchUpInside];
    
    
    //create a footer view on the bottom of the tabeview
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(20, 0, 280, 100)];
    [footerView addSubview:btnDeco];
    [footerView addSubview:btnChange];
    
    tableView.tableFooterView = footerView; 
    [footerView release];
    
    [[self view] addSubview:tableView];
    

提交回复
热议问题