logo
down
shadow

how to show UIAlertController in a custom UITableViewCell in button click using swift code?


how to show UIAlertController in a custom UITableViewCell in button click using swift code?

By : sdfasdfsdcvasdfwef
Date : November 20 2020, 01:01 AM
it helps some times i found a solution. following are code for above question. write the following code for button in viewcontroller where table view are present.
code :
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let deerNameCell: CustomCellDeerCalls = tableView.dequeueReusableCellWithIdentifier("Cell") as CustomCellDeerCalls
    let deercallcell=arrayOfCallsName[indexPath.row]

    deerNameCell.DeerCallNameLabel.text=deercallcell.callName
    deerNameCell.playButton.tag=indexPath.row
    deerNameCell.detialsInfoButton.tag=indexPath.row
    deerNameCell.detialsInfoButton.addTarget(self, action: "showAlert:", forControlEvents:UIControlEvents.TouchUpInside)

    return deerNameCell

}
   func showAlert(sender:UIButton!)
{
    println(sender.tag)
    let deercallcell=arrayOfCallsName[sender.tag]
    var alert = UIAlertController(title: deercallcell.callName, message: arrayOfDetialsInfoDeerCalls[sender.tag], preferredStyle: UIAlertControllerStyle.Alert)
    alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))

    self.presentViewController(alert, animated: true, completion: nil)

}


Share : facebook icon twitter icon
How to add a button with click event on UITableViewCell in Swift?

How to add a button with click event on UITableViewCell in Swift?


By : user3605031
Date : March 29 2020, 07:55 AM
I wish this helpful for you Popular patterns for solving this problem are closures and delegates. If you want to use closures, you would do something like this:
code :
final class MyCell: UITableViewCell {
    var actionBlock: (() -> Void)? = nil
    @IBAction func didTapButton(sender: UIButton) {
        actionBlock?()
    }
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - > UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("MyCellIdentifier") as? MyCell
    cell?.actionBlock = {
       //Do whatever you want to do when the button is tapped here
    }
    protocol MyCellDelegate: class {
        didTapButtonInCell(_ cell: MyCell)
    }

    final class MyCell: UITableViewCell {
        weak delegate: MyCellDelegate?
    @IBAction func didTapButton(sender: UIButton) {
        delegate?.didTapButtonInCell(self)
    }
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - > UITableViewCell {

    let cell = tableView.dequeueReusableCellWithIdentifier("MyCellIdentifier") as? MyCell
    cell?.delegate = self
extension MyViewController: MyCellDelegate {
    didTapButtonInCell(_ cell: MyCell) {
       //Do whatever you want to do when the button is tapped here
    }
}
Show an UIAlertController from a button on an UITableViewCell

Show an UIAlertController from a button on an UITableViewCell


By : Richy Sandoval
Date : March 29 2020, 07:55 AM
With these it helps This is what I coded inside a button in a UITableViewCell. , It crashed because of this line
code :
shareAlert.presentViewController(shareAlert, animated: true, completion: nil)
shareAlert.presentViewController(shareAlert, ...) 
yourCurrentViewController.presentViewController(shareAlert, ...)
Button of UIAlertController changes its color on click. How to solve? - Swift

Button of UIAlertController changes its color on click. How to solve? - Swift


By : jisha
Date : March 29 2020, 07:55 AM
I wish this help you this is the Bug in iOS 9.0, see apple Community bug reports, may be it fixed on iOS 9.1
for additional reference see this link
UIAlertController Giving error? Please Give the code for UIAlertController with Array of Strings As Buttons in Swift

UIAlertController Giving error? Please Give the code for UIAlertController with Array of Strings As Buttons in Swift


By : newby
Date : March 29 2020, 07:55 AM
this one helps. First of all I going to explain you why this happen, you can see if you touch any of your buttons always the output result of the call of NSLog("%@",String(i)) is plLists.count - 1, this is because you're trying to set always the index of the for statement inside the closure of the actions you're adding. The variable is outside the scope of the closure.
The main problem is that always the reference retained inside the closure in your case is the last index of the array, because as you said is increased and finally when it finish is assigned the value.
code :
func presentAction() {

    let alertA = UIAlertController(title: "PlayLists", message: "Select From PlayLists Below", preferredStyle: .ActionSheet)
    let action = UIAlertAction(title: "Cancel", style:  .Default, handler: nil)

    let plLists = ["List1", "List2", "List3", "List4"]
    for(var i = 0; i < plLists.count; i++) {
        alertA.addAction(UIAlertAction(title: plLists[i], style: .Default, handler: self.handlerForAction)) 
    }

    alertA.addAction(action)
    self.presentViewController(alertA, animated: true, completion: nil)
}

func handlerForAction(action: UIAlertAction) {
    print(action.title!)
}
Add UIAlertController in a custom UITableViewCell in button click using swift code?

Add UIAlertController in a custom UITableViewCell in button click using swift code?


By : Aatmika Shree
Date : March 29 2020, 07:55 AM
I hope this helps you . I have menuTablecontroller in which I took customcell with two labels and another Inner tableviewcontroller . Now here in Innertableview I have ItemCustomcell with two labels and a button. I have to add Alertviewcontroller on clicking this button. I have tried by creating protocols into the menuTabletablecontroller set the delegate but its not working .. , You forgot to actually set the delegate:
code :
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("itemCell") as! ItemTableViewCell
    cell.delegate = // Your MenuTableViewController
    return cell 
 }
class MenuTableViewController: UITableViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.showAlert(_:)), name: "showError", object: nil)
    }


    func showAlert(sender: NSNotification) {
        let title = sender.object!["title"]
        let message = sender.object!["message"]

        let alert = UIAlertController(title: "Choose Mode of Order", message:"", preferredStyle: UIAlertControllerStyle.Alert)
        alert.addAction(UIAlertAction(title: "ok", style: UIAlertActionStyle.Default, handler: nil))

        self.presentViewController(alert, animated: true, completion: nil)
    }

    ....
}

class ItemTableViewCell: UITableViewCell {

    @IBAction func OrderBtnPressed(sender: AnyObject) {
        NSNotificationCenter.defaultCenter().postNotificationName("showError", object: [ "message" : "A message", "title" : "A Title" ])
    }
}
Related Posts Related Posts :
  • Unclear about releasing CFDictionaryRef
  • CordovaError: Promise rejected with non-error: Error code 65
  • How to append NSMutable strings into a UILabel
  • CustomCell label value does not change
  • Display ad in iAd Bannerview iAd Network
  • Warning: "Could not get traitsetID for iPhone11,6" (Assets.xcassets)
  • Changing root view controller after iOS app has loaded.
  • SocketRocket and iOS certificate pinning
  • Draggable UIButton Snap To a Circle Path
  • Running FireBase in the background
  • resizing UIPopoverController to fit UITableController
  • UICollectionView Exception Crash
  • targeting iOS5 - will it work on iOS6 also?
  • FBLoginView get email
  • Scale UIImages height to UIImageView height
  • Creating a custom progress indicator in ios
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • 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
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org