Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift: Buttons not working #192

Open
simongiesen opened this issue Oct 7, 2020 · 9 comments
Open

Swift: Buttons not working #192

simongiesen opened this issue Oct 7, 2020 · 9 comments

Comments

@simongiesen
Copy link

Hi everybody!

I try to add an action handler and alternative handler. It does not work ... Can anybody help me?

let bulletinManager: BLTNItemManager = {
let rootItem = BLTNPageItem(title: "Welcome")

        rootItem.descriptionText = "Would you like to add Sample Data to your database?"
        rootItem.actionButtonTitle = "Add"
        rootItem.alternativeButtonTitle = "Not now"
        rootItem.isDismissable = false
        
        rootItem.actionHandler = { (item: BLTNActionItem) in
            item.actionButtonTitle = "tapped"
        }
        
        
        
        rootItem.alternativeHandler = { (item: BLTNActionItem) in
            print("Alternative button tapped")
        }
        
            return BLTNItemManager(rootItem: rootItem)
        }()

`

@alexisakers
Copy link
Owner

Hi there, what version are you using? Does the issue reproduce with 5.0.0-rc.2?

@simongiesen
Copy link
Author

Hi there, what version are you using? Does the issue reproduce with 5.0.0-rc.2?

yes

@alexisakers
Copy link
Owner

I cannot reproduce the issue. If you could provide more details about how you present the bulletin it would be really helpful!

@rdunlocked18
Copy link

issue persist not able to click the buttons handlers ain't working .

@alexisakers
Copy link
Owner

@rdunlocked18 can you please share:

  • if you use the Objective-C or Swift version
  • what version of iOS you can reproduce this on
  • a code sample that reproduces the issue

Thank you!

@rdunlocked18
Copy link

@alexisakers

below is the code snippet i am using for button actions handling in iOS 14 , simulator + tableview on Xcode 12 with latest version of your POD.

` func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = scheduleTableMain.dequeueReusableCell(withIdentifier: "schCell" , for: indexPath) as! ScheduleTableViewCell
let classes : ScheduleClasses

    classes = classList[indexPath.row]
    let boardManagere : BLTNItemManager = {
        
        let item = BLTNPageItem(title: classes.name)
        item.requiresCloseButton = false
        item.descriptionText = classes.description
        //item.image = UIImage(named: "circleLogo")
        item.actionButtonTitle = "Join Class"
        item.alternativeButtonTitle = "More Info"
        item.isDismissable = true
        item.appearance.actionButtonColor = UIColor(named: "someCyan") ?? UIColor.blue
        item.actionHandler = {(item: BLTNActionItem) in
                print("Action button tapped")
        }
        item.alternativeHandler = {(item: BLTNActionItem) in
            print("Action button tapped")
        }
        
        return BLTNItemManager(rootItem: item)
        
    }()
    boardManagere.backgroundViewStyle = .blurredDark
    boardManagere.showBulletin(above: self)

} `

Screenshot of text being fetched over the title and i need that join button to be working that is really important :)

simulator_screenshot_CEA598C0-4AE1-4DA1-A064-316090C32E37

@alexisakers
Copy link
Owner

@rdunlocked18 Ah okay - so the issue here is that you don’t keep a reference to the bulletin manager. The object gets deallocated when the table view delegate method returns. You need to keep a reference to it, you can look at the example project to see how it’s done.

@simongiesen it’s probably the same issue for you, actually. Can you double check?

@rdunlocked18
Copy link

@alexisakers

i need to trigger BLTN on TableView Click can u hint me out how can i ?.. even if i lazy var it in the class the extension wont let the vars get through the mainClass so what should i do ? where should i create a reference of BLTNItemManager to get it onClick of tableView single cell .. i am a bit new in iOS

@alexisakers
Copy link
Owner

You can have an optional variable on the class that’s presenting it:

var bulletinManager: BLTNManager?

and set it in did tap table view cell after you create it:

let bulletinManager = ... (your code snippet)
self. bulletinManager = bulletinManager

And once you dismiss it, call that in the dismissal handler:

self.bulletinManager = nil

Again, please look at the example project for help with the dismissal handlers and setting up the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants