swift 点击cell没反应,点击后应该跳到指定页面

本教程详细介绍了如何在iOS应用中设置tableView的数据源和代理,实现图标点击后的页面跳转。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

拖入一个tableView之后,要设置他的 关联右键点击tableView

将datasource 和 delegate 连接到三个图标的第一个(像古代硬币一样的那个)
这里写图片描述
之后再点击cell 之后就可以跳刀指定的页面了

import UIKit

class ViewController: UIViewController {

    @IBOutlet weak var testTable: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


   func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete method implementation.
        // Return the number of rows in the section.
        return 5
    }



    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{

       let cell:UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "cell")

        return cell
    }

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){


            self.performSegueWithIdentifier("page1", sender: self)







    }




    //如果需要传值的话,调用这个方法

   // override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {


      //  var theSegue = segue.destinationViewController as! Test1


        //   let navigationEdit = segue.destinationViewController as! UINavigationController

         //   let viewContrEdit = navigationEdit.topViewController as! Test1



  //  }



}

别忘了给你的segue 定义identity,我这里叫“page1”

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值