Close popup UITableViewController view - iphone

How do I know when the view got closed? Am currently using the delegate pattern, capture viewDidDisappear to fire the event... Is this the correct one to use? Downside of viewDidDisappear is that when my view move to a sub-view the event still fires.
Its a custom view that i made that exptend UITableViewController... In that table you got a list of options that you manage, so when moving between those screens I don't want my event to fire.. I only want it to fire when I close the actual view.

now just see when your UITableView begin open at that time you set the bool value like...
first define this variable global in your .h file like bellow
BOOL isTableOpen;
and after that in your .m file
set yes when your tableview is open with button tap event or anything else which you used...
isTableOpen = YES;
after when your pop-up view or UITableview closed at that time set value NO like
isTableOpen = NO;
and check in your viewDidDisappear: that if isTableOpen is true then do nothing otherwise yes...
-(void)viewDidDisappear:(BOOL)animated{
if(isTableOpen){
//call your method which you want...
}
}
i hope this help you or get some Idea ..
:)

Related

iOS: How to know if viewDidLoad got called?

Is there a BOOL or some other way of knowing if viewDidLoad: has been called?
I need to change a view property every time my view has entered active, but if the view hasn't ever been loaded, I don't want to prematurely trigger viewDidLoad:. If there isn't way of easily telling if viewDidLoad: has been called, I'll simply add a BOOL called loaded set to NO in the view controller init, then change the view properties after entered active if loaded is YES or in viewWillAppear: if loaded is NO then set loaded to YES.
Use isViewLoaded. Other than that it does exactly what you want, there's not that much to say about it. The documentation is as simple as:
Calling this method reports whether the view is loaded. Unlike the
view property, it does not attempt to load the view if it is not
already in memory.
Perhaps you should init your UIView in viewDidLoad, and then change it in whichever way you need to inside viewWillLayoutSubviews.
Here's the pedantic answer to this question. If you want to know when viewDidLoad has been triggered, you have to implement viewDidLoad in your view controller
- (void)viewDidLoad
{
[super viewDidLoad];
viewDidLoadCalled = YES; // Not actually the best way to do this...
// Set up more view properties
}
But as Tommy says, you actually need to use isViewLoaded. This gets around the problem of doing a check like
if (!self.view) {
// do something
}
which inadvertently loads the view by virtue of asking about it.
Be aware that by the time viewWillAppear: is called, the view will always have loaded. Also, on older (pre-iOS 6 I think) releases, the view can unload and be reloaded many times over a view controller's lifetime. Refer to the very nice Big Nerd Ranch view lifecycle diagram for the old behavior. It's almost the same in iOS 6+, except that the view doesn't unload under low memory conditions and viewDidUnload doesn't get called:

Prevent a window to open in viewWillAppear

In iOS, is there a possibility of stopping a view from loading in the viewWillAppear ?
Something like [self close]; ?
What I am trying to do is:
create a view with an object partially loaded
display the view
in the viewWillAppear, I finish the object loading and fill the view fields
if the object loading fails, I do not want to show the view
I know that it is not really the good way to do that,
but it's existing code that I do not want to change too much.
I'm not sure if I misunderstood your question, but if you just try to have a view inside a viewController not to be shown at the beginning and to appear later you can easily viewName.hide = YES; it in viewWillAppear and then viewName.hide = NO; when you want it to be shown.

SearchBar not working when search button is clicked

Can anyone help me out, i am working with UISearchBar and want that when i write anything in SearchBar and press enter key, it will start desired operation...
I have read searchBarSearchButtonClicked function will get called once the “Search” button will be clicked on the pop-up keyboard window. But it is not called:(
I have implemented as:
(void) searchBarSearchButtonClicked:(UISearchBar*) searchContact
{
//do some thing
}
i have checked by placing breakpoints infact this function is not being called....
any idea??
Thanks!!
Did you assign delegate to that viewcontroller which implemented "searchBarSearchButtonClicked" ?
You need to assign delegate like this.
searchBar.delegate =self;
You need to implement the UISearchBarDelegate protocol and set the delegate of the textfield to the class which implements this protocol.
This is the reason why the delegate is not getting called.
You can try this,
In IB set the delegate to file's owner and implement the delegate.
In Code, if you hold reference to the search bar, then on viewDidLoad
searchBar.delegate = self;

Problem showing some controls that are part of an UIView

In my app I have a custom UIView subclass (let's call it MyView) which contains three buttons and two labels. I add this view to a view controller which also has a table view (I add the instance of MyView at the bottom).
Because of the business logic rules, the labels and one button out of three are hidden in the beginning. So I do this in viewDidLoad:
self.myView.label1.hidden = YES;
self.myView.label2.hidden = YES;
self.myView.button1.hidden = YES;
which works fine. So these three are hidden and the remaining two buttons are visible.
Now this view controller is also a delegate for another class. At some point in time an event occurs in this other class which calls a notification method in my view controller.
In this notification method I have now to show the hidden controls. So I obviously tried the following:
self.myView.label1.hidden = NO;
self.myView.label2.hidden = NO;
self.myView.button1.hidden = NO;
but it doesn't work, they don't appear.
Any idea what I'm doing wrong? Do I need to somehow "repaint" self.myView after this so that the controls become visible? What am I missing here?
Many thanks in advance!
Edit
I have added some NSLogs after setting them visible and the logs show something like this:
label1.hidden = 0
label2.hidden = 0
button1.hidden = 0
So as per the logs, they should be visible.
Ok, so I solved the problem. I moved the code that sets the visibility of the controls in another method and I call this method like this:
[self performSelectorOnMainThread:#selector(updateControls) withObject:nil waitUntilDone:NO];
So what do you know, the notification method was called in another thread (I didn't know this, the library I am using is actually not mine and there's nothing in the docs about this fact).
Anyway, it's nice that it works now.
Thanks all!
Have you confirmed that your notification method is getting called? You shouldn't need to specifically refresh the view, but if you are sure that your method is called, then you can also try adding [self.myView setNeedsDisplay]; into your notification method.

navigationItem.title doesnt get refreshed

I have a RootViewController and a SubViewController. I traverse the views in either direction. The RootViewController is a UITableView SubClass. Depending upon the row selected I want to change the title of the subview using self.navigationItem.title = [chunks objectAtIndex:1];
It works when the subview is first time loaded. But when I return to the RootViewController and load the subview again the previous title persists.
Any ideas what am I missing out on?
In your particular case, you probably want to set your title in viewWillAppear: so that the title gets set every time the view comes on the screen.
I just tried it in an app of mine. When I set the title using
self.navigationItem.title = #"Foo"
the name in the navigation bar changes instantly. I think you have a bug somewhere else that you code is only getting called the first time you invoke your SubViewController. Stick a break point on that line and see if it actually gets called a second time. Or perhaps [chunks objectAtIndex:1] is always returning the same string.
Or perhaps I'm not understanding your question. As far as I can tell it does work like you are expecting it to.
I guess you are trying to change the title in the viewDidLoad method. The viewDidLoad is called only the first time the view is loaded. In case you are reusing the same viewcontroller's instance, viewDidLoad will be called only once.
Instead try setting the title in viewWillAppear method. This method is called every time the view is going to be displayed. That should work.