Add button in tableview footer

后端 未结 3 1469
轻奢々
轻奢々 2021-02-19 07:18

I have tableview in one viewcontroller. I have one section in that. I want to add button in footer. I have written this code but footer view is not displaying.

-         


        
3条回答
  •  醉酒成梦
    2021-02-19 08:00

    Same code in swift

    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
            return 100.0
        }
        func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    
            let footerView = UIView(frame:CGRectMake(0,0,320,40))
    
            let loginButton = UIButton(type: .Custom)
            loginButton.setTitle("LOGIN", forState: .Normal)
            loginButton.addTarget(self, action: "loginAction", forControlEvents: .TouchUpInside)
            loginButton.setTitleColor(UIColor.whiteColor(), forState: .Normal)
            loginButton.backgroundColor = UIColor.blueColor()
            loginButton.frame = CGRectMake(0, 0, 130, 30)
    
            footerView.addSubview(loginButton)
    
            return footerView
        }
    
        func loginAction()
        {
            print("Hello");
        }
    

提交回复
热议问题