Swift: How do I link an action to a view inside of a tableViewCell?

Swift: How do I link an action to a view inside of a tableViewCell?

By : user2954897
Date : November 22 2020, 10:33 AM

Share : facebook icon twitter icon
Trigger an action from a TableviewCell in swift

Trigger an action from a TableviewCell in swift

By : Titifrim
Date : March 29 2020, 07:55 AM
I hope this helps . I'm new to Swift and I'd like know how to trigger an action when a cell in my TableviewController is tapped. I created the configuration of my tableview completely in the Storyboard, so the cells were not created manually by coding. I also edited the tag-field of this cells in order to address them, but I am wondering how. , Just add this code to your UITableViewController.
code :
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
           //In here do whatever you want to do when the user selects a row
Swift 3 - button in .xib custom tableviewcell is not performing action

Swift 3 - button in .xib custom tableviewcell is not performing action

By : Ricky Charles
Date : March 29 2020, 07:55 AM
Hope this helps You need to use addTarget(_:action:for:) method to add the action for your button not the actions(forTarget:forControlEvent:).
The function actions(forTarget:forControlEvent:) returns the actions that have been added to a control. It doesn't add a target/action.
code :
cell.myButton.addTarget(self,action: #selector(myAction(sender:)), for: .touchUpInside)
Swift - Stepper in TableViewCell - Action not Responding

Swift - Stepper in TableViewCell - Action not Responding

By : hepatus
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further You've disabled the user interaction in your cell for row at index method:
code :
cell.isUserInteractionEnabled = false;
How to present a separate View Controller when click on a button inside a custom TableViewCell Swift 4?

How to present a separate View Controller when click on a button inside a custom TableViewCell Swift 4?

By : hspinks
Date : March 29 2020, 07:55 AM
This might help you I have 2 view controller,MainVC and PopUpVC. MainVC have a tableView with tableViewCell class.Every cell have a ShowButton.So what I want to do is,when I click on ShowButton,PopUpVC will show on top of MainVc , Try this
code :
 override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    if(segue.identifier == "popVc")

         let newVC = segue.destination;

        self.setPresentationStyleForSelfController(selfController: self,presentingController: newVC)



 func setPresentationStyleForSelfController(selfController:UIViewController,presentingController:UIViewController)
   if #available(iOS 8.0, *)

        //iOS 8.0 and above

        presentingController.providesPresentationContextTransitionStyle = true;

        presentingController.definesPresentationContext = true;

        presentingController.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext


         presentingController.modalPresentationStyle = UIModalPresentationStyle.currentContext

        selfController.navigationController?.modalPresentationStyle = UIModalPresentationStyle.currentContext

Action when tap on tableViewCell (swift)

Action when tap on tableViewCell (swift)

By : user3691143
Date : March 29 2020, 07:55 AM
help you fix your problem You need to set delegate and dataSource and implement didSelectRowAt correctly
code :
class ViewController: UIViewController , UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        // Do any additional setup after loading the view.
        self.tableView.delegate = self
        self.tableView.dataSource = self

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titolo.count
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cellReuseIdentifier")!
        cell.textLabel?.text = text1
        cell.detailTextLabel?.text = text2
        return cell
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         print("test tap cell")
Related Posts Related Posts :
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • How to change the UILabel content by tapping?
  • Adding checkmark to selected table cell also checks another table cell
  • UICollectionView cellForItemAtIndexPath indexPath row is nil
  • Resize and set quality on JPEG image while retaining EXIF in iOS
  • How to push rootviewcontroller in Ios
  • How to add UIBarbuttonItem at centre on UInavigationbar in iOS
  • Would this IOS device test crash be expected
  • PickerView not showing any values
  • How to set root view controller in storyboard animated with navigation controller programmatically
  • Can anyone suggest me the effective way to deal with s3 upload fail because of timezone difference issue?
  • Getting list of files in documents folder
  • Error while using Realm Object as a singleton. Is it a good idea?
  • inserting into SQLite database
  • More nodes than I should
  • Facebook IOS SDK navigate to another controller after login not working
  • Swift Array - use "Contains" of type AnyObject
  • Sidebar menu with indicate navigationbar on iOS
  • Programmatically set size of UIView from Storyboard
  • Navigation bar blink
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org