This is more of a programming practice and design issue than a straight coding problem.
I have five buttons on a UITabBar. When I switch from any of them to the one in the middle, I want to have a UIActionSheet pop up and give two options and a cancel button. In my test app I added code in viewWillAppear to bring up the sheet so that the user can select which option they want and the view associated with that button will change based on the user's selection. The problem is that I assumed the action sheet would delay the exit of viewWillAppear, but while the action sheet is up, viewDidAppear gets called. If viewDidAppear gets called while the action sheet is still up, the view doesn't conform to the user's selection.
That said, I had this other solution of determining which button was selected before switching the view. That is, create a delegate for the tab bar, determine if that speci开发者_如何转开发al button was selected, and if it was, bring up the action sheet BEFORE switching views.
I'm not new to iPhone/Cocoa programming, and there are always different solutions to a problem, but I'm asking here because I wanted to know if delaying the exit of viewWillAppear is something people do (I'm thinking not), and which solution would be the better one.
If I would do the same thing I would have gone the delegate route and check which tab was selected, present the action sheet and handle the action before any views were changed. That design make sense to me.
精彩评论