Uibarbuttonitem Action Not Work Uitableview Cell

UIBarButtonItem action not work UITableView cell

Use this :

Inside

UIBarButtonItem(title: Wordings.BTN_CHOOSE, style:UIBarButtonItemStyle.done, target: nil, action: #selector(self.pickerChildrenDonePressed)

change target to self instead of nil

@IBAction of UIBarButtonItem not being called from UIToolbar inside generic cell of tableview

Ok, so the problem was that I forget to mark the UIToolbar as lazy so I couldn't use class properties and functions.

I don't know why Xcode didn't warn me about this... I think this could be reported.

UIBarButtonItem not firing up selector action

The code you provided should be working so you need to provide more context (show more of your view controller class where this is implemented).

UIKit provides a set of standard UIBarButtonItems called system items. These happen to include an 'add' item, which is displayed as a plus-sign and used throughout iOS. Using this item solves question 2 and 3.

UIBarButtonItem has a convenience constructor for initialising a system item. See the working example below:

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()

let addProdButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addProduct))
navigationItem.leftBarButtonItem = addProdButton
}

@objc func addProduct() {
print("addProduct() called")
}
}

Action not being triggered for UIBarButtonItem

You are initialising the UIToolbar without a frame and that would make it not register any touch events because they would be out of the toolbar's bounds.

Replace let accessoryView = UIToolbar() with something like let accessoryView = UIToolbar(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 44))

Or you can call accessoryView.sizeToFit() before return accessoryView

Why does a UIBarButtonItem action not trigger in a separate class?

Th problem here is that you're instantiating NavigationBarHandler inside viewDidload() which is why the memory reference dies after viewDidLoad() finishes. What you should do is to create the variable outside like this.

class ContactsController: UIViewController {

var navigationBarHandler: NavigationBarHandler!

// MARK: View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()

view.backgroundColor = .red
self.title = "Kontakte"

self.navigationBarHandler = NavigationBarHandler(navigationItem: self.navigationItem)
navigationBarHandler.setupNavigationBar()
}
}

This way the memory reference stays.

UIBarButtonItem Action created in another class not firing (swift)

Echoing what Huy Nghia mentioned in the comments, if you set the target to nil, you've effectively send a message to a nil object, which does nothing.

[nil doneButtonAction] is effectively a no-op



Related Topics



Leave a reply



Submit