Is it possible to call a UIEvent between viewWillAppear and viewDidAppear? - iphone

Is it possible to handle UIEvents between viewWillAppear and viewWillDisappear?
For example:
Let's say I have a view controller with a UITableView.
When pressing a cell I push a another view controller to the navigation controller (And display it of course).
Is it possible that after the viewWillAppear event of the pushed view (And before the viewDidAppear) I can still press one of the cells in the UITableView?
I am asking this because I am seeing this in the logs of my application and I Never thought that such a thing could be possible..
What do you guys(Or girls) think?
Thanks!

I have one idea may this work,
you use performSelector in viewWillAppear with 0.01 or another time with Delay Parameter and call your method here,
hope,this help you.
:)

Related

Back button in UINavigationController

So, I am well aware that when the back button is pressed in classes embedded in UINavigationControllers, the previous view's viewDidAppear() method is called. However, I need the viewDidLoad() method to be called, much like it is with a push segue into a scene. Is there a possible way to do this? Maybe by modifying the method that is called when the back button is pressed? What is the method that is called when the back button is pressed? Thanks.
Firstly viewWillAppear and then viewDidAppear is getting called on push back. And for lazy loading of views, it is preferable to add/operate UI subviews in viewWillAppear, and make them set view to nil in viewDidDisappear for memory management.
viewDidLoad is only called when the view has loaded. There's a difference between views being loaded/unloaded and them appearing/disappearing: a view can disappear without being unloaded. Usually iOS will not unload a view, even if it is hidden/replaced by by another view, unless a low memory situation occurs.
Don't ever call viewDidLoad etc. yourself (except for the super call in subclass overrides).

Where is the proper place to reload TableView data?

My project has a few view controllers, let's say A and B.
In A I have a UITableView. When a row is selected, I pass the row number and cell text to view B, then pushViewController B.
In view B, when hitting the 'done' button I make changes to the underlying data (right now a Singleton array) and then pop back to view A. In view A viewDidAppear, I reload the UITableView to see the new data.
Is this the best way to do it?
Or should I be reloading the UITableView when the 'done' button is hit?
If so, how do I reload a Table in view A from within view B?
Thanks.
It is better to reload the data directly when you hit the "Done" button. You can do that by a Notification Center. Please check this link for more details about Notification Center.
ViewController "A" should certainly be responsible for deciding to reload the table data. I would consider putting that into the "viewWillAppear" method of ViewController A. That way the table is reloaded before being displayed to prevent and "flickering".
There is nothing very wrong about this, except that your table will be reloaded every time it's viewDidAppear is called, which may not be very good depending upon the size of the table. The best way would be to use #protocol and make a quick delegate design pattern, though this might seem unnecessary headache if you are not used to it. You can also use NSNotifications, although I would not insist using it in this case, as there are not many observers listening to the event.
Instead of using NSNotification. You can assign view A to be view B's delegate which is a much cleaner design pattern.
So in view A it would look like
ViewB *b = [[ViewB alloc] init];
b.delegate = self;
and the in viewB when you are done making modification u call
[delegate updateTable];
where in updateTable is a #required method in the delegate declaration and since its required viewA will need to implement it if it says it conforms to that delegation.
Also this method will be called before you pop the viewB out.

How to tell when a subView is removed a UIView

Basically i wanted to implement a popup UIView so i followed what was posted here
POP-UP UIView "IMDB App" style
This works very well. However i have one query. My main view is a tableView. so when a view is popped up i disable scrolling in the table. Now when the popup subView is removed, i need to re-enable scrolling. How do i achieve that? i can't use willRemoveFromSuperview because the popup view is loading a different NIB altogether.
Should i use Notifications?
hope i was clear with explaining the scenario.
Thanks in advance!
Feloneous Cat has the correct answer. This is the perfect use a #protocol in your popup view along with a registered delegate. Something is triggering that popup view to close. Whatever that trigger is, call the protocol and the delegate can handle the situation as needed.
Furthermore, when protocols are used correctly, your code becomes very reusable within a project as well as in other projects.
What you could do is subclass UIView and override removeFromSuperview to send a notification. I don't think there's ever a case where a view gets removed without using the removeFromSuperview method.

How to tell when a view has become active

I'm using a navigationController to push a new view onto the stack. Once I'm done with that view I pop it. I want the original or root view at the bottom of the stack which then becomes active to know when this has happened to it can call a method on itself
There are two options
1. implement -(void) viewWillAppear:animated: This is often a useful strategy for knowing that a view is about to become visible. If you are always doing the same thing when this happens, then this is quick and easy.
2. Send a NSNotification. This is useful when you want your underlying view to perform some action in response to a particular event happening elsewhere.
Use the viewWillAppear delegate. It is called right before showing the view.

iPad viewWillAppear and presentModalViewController problems

In the iPhone, I have a tableview, and touching the cells, I have one method calling presentModalViewController, and opening another view, with email and this kind of stuff.
When the user press the cancel button, the viewWillAppear method in the previous view is called.
So far, so good. But in the iPad, the viewWillAppear is only called the first time that the view appears, anyone knows if this is a bug or it's right?
I tried to implement the
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
with no success.
Does anybody know how to fix this without doing any delegate method from scratch?
Thanks in advance
Since view controllers presented modally don't necessarily completely cover up the underlying view on iPad, the viewWillAppear method does not fire when said modal view controllers get dismissed. I rely on delegate methods to announce to the original view controller the actions of the modal view controller. I think it's the best way to go.
Based on guesswork, rather than reading, testing or anything useful really, but therefore not covered under the NDA...
Is viewWillDisappear being called when you presentModalViewController ? It may be that it doesn't think the modal view obscures the original view fully, therefore (unlike the iPhone) both exist at once ?
Chances are it's a bug, I would file a bug report with apple here.