ios – 如何在swift 2.2中的tableview标题中创建条形按钮或UIButton?

ios – 如何在swift 2.2中的tableview标题中创建条形按钮或UIButton?,第1张

概述如何在tableview标题中创建条形按钮或UIButton,当我点击tableview标题按钮时,它应该转到另一个Viewcontroller.我怎样才能通过Progarm实现这一目标.请帮帮我们 喜欢 func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { initial 如何在tablevIEw标题中创建条形按钮或UIbutton,当我点击tablevIEw标题按钮时,它应该转到另一个VIEwcontroller.我怎样才能通过Progarm实现这一目标.请帮帮我们解决方法 喜欢

func tableVIEw(tableVIEw: UItableVIEw,vIEwForheaderInSection section: Int) -> UIVIEw? {

initially get the frame of your tablevIEw

let frame: CGRect = tableVIEw.frame

set the frame for UIbutton where is comes in VIEw

let DoneBut: UIbutton = UIbutton(frame: CGRectMake(100,200,50)) //frame.size.wIDth - 60DoneBut.setTitle("Done",forState: .normal)DoneBut.backgroundcolor = UIcolor.redcolor()

if you are using swift 2.2 call the selector as follows

DoneBut.addTarget(self,action: #selector(VIEwController.buttonTapped(_:)),forControlEvents: .touchUpInsIDe)

if you are using swift 2.1 call the selector as follows

DoneBut.addTarget(self,action: Selector("buttonTapped:"),forControlEvents: .touchUpInsIDe)button.addTarget(self,forControlEvents: .touchUpInsIDe)

create the UIVIEw reason vIEwforheader returns UIVIEw and add button to that subVIEw

let headerVIEw: UIVIEw = UIVIEw(frame: CGRectMake(0,frame.size.wIDth,frame.size.height))headerVIEw.addSubvIEw(DoneBut)return headerVIEw}

call method like

func buttonTapped(sender: UIbutton) {//button Tapped and open your another VIEwController}

更新的答案

func tableVIEw(tableVIEw:UItableVIEw,vIEwForheaderInSection section:Int) – > UIVIEw的?
    {

let frame: CGRect = tableVIEw.frame    let DoneBut: UIbutton = UIbutton(frame: CGRectMake(frame.size.wIDth - 200,150,50)) //    DoneBut.setTitle("Done",forState: .normal)    DoneBut.backgroundcolor = UIcolor.redcolor()    DoneBut.addTarget(self,forControlEvents: .touchUpInsIDe)    DoneBut.backgroundcolor = UIcolor.bluecolor()    let headerVIEw: UIVIEw = UIVIEw(frame: CGRectMake(0,frame.size.height))      headerVIEw.backgroundcolor = UIcolor.redcolor()    headerVIEw.addSubvIEw(DoneBut)    return headerVIEw}func tableVIEw(tableVIEw: UItableVIEw,heightForheaderInSection section: Int) -> CGfloat {    return 50.0}func buttonTapped(sender: UIbutton) {    //button Tapped and open your another VIEwController}

产量

总结

以上是内存溢出为你收集整理的ios – 如何在swift 2.2中的tableview标题中创建条形按钮或UIButton?全部内容,希望文章能够帮你解决ios – 如何在swift 2.2中的tableview标题中创建条形按钮或UIButton?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1022660.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存