Currently I've got a class popping up UIAlertView
s here and there. Currently, the same class is the delegate for these (it's very logical that it would be). Unfortunately, these UIAlertView
s will call the same delegate methods of the class. Now, the question is - how do you know from which alert view a delegate method is invoked? I was thinking of just checking the title of the alert view, but that isn't so elegant. What's the most elegant way to handle several UIAlertView
s?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Unable to process app at this time due to a genera
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
You can overcome this whole ordeal and prevent yourself from using tags by enhancing UIAlertView to use block callbacks. Check out this blog post I wrote on the subject.
easier & newer
all done!
FYI, if you want to target just iOS 4 users (which is reasonable now that ~98.5% of clients have at least iOS 4 installed), you should be able to use Blocks to do really nice inline handling of UIAlertViews.
Here's a Stackoverflow question explaining it:
Block for UIAlertViewDelegate
I tried using Zachary Waldowski's BlocksKit framework for this. His UIAlertView(BlocksKit) API reference looked really good. However, I tried to follow his instructions to import the BlocksKit framework into my project, but unfortunately I couldn't get it to work.
So, as Can Berk Güder suggests, I've used
UIAlertView
tags for now. But at some point in future I'm going to try to move to using Blocks (preferably one which supports ARC out of the box)!I've always thought using tags is a bit of a hack. If you do use them, at least set some defined constants for the tag numbers.
Instead, I use properties like this:
In the interface section:
Creating the alert view:
Delegate method:
Tag the
UIAlertView
s like this:and then differentiate between them in the delegate methods using these tags: