My application is view based in my app in one view i write view will appear but this method doesn't call. My code is
-(void)viewWillAppear:(BOOL)animated
{
NSLog(#"view will Appear");
[tableView reloadData];
}
Can anyone tell why viewWillAppear method not called.
Sorry I forgot To tell You That This method call first time but when i remove a subview from this view viewWillAppear not called. Please Suggest me how to solve this problem.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(#"view will Appear");
[tableView reloadData];
}
if still it is not calling then try to call through code , as per example [classobj viewWillAppear:NO];
The viewWillAppear and other related methods are called to the viewcontroller that are linked with the rootViewController of the mainWindow.
So if you are using a view based application, the viewWillAppear method of the first view controller will work properly and others wont.
I think that the problem you are seeing is that viewWillAppear: is a method on a UIViewController, and not a method on UIView. viewWillAppear: is called on the view controller to indicate that the controller's view will become visible.
If you have added the code above to a class based on UIView, that code won't get called. You need to move that code to your view controller -or- you might achieve the result that you are looking for by implementing the didMoveToSuperview method in your UIView based class instead.
didMoveToSuperview will be called on your view when your view is added to another view using addSubview:.
Hi Here I did instead
[self.view addSubview:viewcontroller.view];
I Used this:
[self presentModalViewController:viewcontroller animated:YES];
and write this method now my problem is solved.
-(void)viewWillAppear:(BOOL)animated
{
NSLog(#"==========view will appear");
}
Related
... I guess.
This is the situation:
here a simple method, in a view controller, where we can push a botton to go in another view:
- (IBAction)actionNext:(UIButton *)sender {
self.numeriUtiliListaViewController = [[ALCNumeriUtiliListaViewController alloc] init];
[self.numeriUtiliListaViewController.view setTag:[sender tag]];
[self.delegate vai:self.numeriUtiliListaViewController title:#"Numeri Utili"];
}
the delegate's method is:
- (void)vai:(id)view title:(NSString *)title
{
ALCParentViewController *viewController = (ALCParentViewController *)view;
viewController.delegate = self;
NSLog(#"tag: %d",[viewController.view tag]);
[self.myNavigationController pushViewController:viewController animated:YES];
}
This system works well, but the only thing is the tag that i've logged in this last method, here it was print correctly, but in the view loaded by the navigation controller, when i try to catch the value in the viewDidLoad, it's 0.
Any ideas?
Thanks in advance
Update 1 2013-01-30:
if i try to print the the tag in the viewWilAppear method of the viewcontroller pushed in the navigationcontroller, i'll give the right value... why? i don't know
Whats happening here is that in your actionNext method, when you are setting the tag of the viewController's view using : self.numeriUtiliListaViewController.view, as soon as you access the view propert of the viewController, viewDidLoad method is called in the viewController. So even before the setTag function is executed, viewDidLoad has already been executed, and it is showing tag = 0. But your viewWillAppear/viewDidAppear methods will be called only when the actual view appears and by then setTag has been executed, so it shows correct value.
Makes sense? Hope this helps
I've spent hours and I cant figure this out. I have a detail view controller (UITableView) which is launched here:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
EventLocationDetailController *newDetailViewController = [[EventLocationDetailController alloc] initWithNibName:#"EventLocationDetailController" bundle:nil];
self.eventDetailController = newDetailViewController;
[self.navigationController pushViewController:self.eventDetailController animated:YES];
[newDetailViewController release];
}
In the detail view controller there is a button method which calls the below method to display a slide-in-slide-out animation confirming the users choice:
-(void)confirmLastActionWithMessage:(NSString *)message {
ConfirmActionViewController *newConfirmActionViewController = [[ConfirmActionViewController alloc] initWithNibName:#"ConfirmActionViewController" bundle:nil];
self.confirmActionViewController = newConfirmActionViewController;
[newConfirmActionViewController release];
[[self.view superview] addSubview:self.confirmActionViewController.view];
}
Protocol method called by the ConfirmActionViewController indicating that the animation is finished.
-(void)didFinishConfirmDisplay:(UIView *)viewToRemoveFromSuperview {
[viewToRemoveFromSuperview removeFromSuperview];
}
This works perfect the first time I press the button. If I pop the detail controller and push it back on to the stack and press the button again, nothing happens and the detail controller's superview is nil every time I invoke the method after that. Superview is not nil in the viewWillAppear method for the detail view, only when It gets to the confirmLastActionWithMessage method. No other user interaction happens in between. How do I get the superview back? I have a similar code that works without animation.
I've also noticed that the detail view controller hasn't called dealloc when popped off the stack. Not sure where the problem is.
Thanks.
EDIT 1
OK. I replaced the addSubview line with this one:
[self.view insertSubview:self.confirmActionViewController.view atIndex:0];
and the animation view appeared underneath one of the table cells. Could one of the table cells steal the superview?
Well I don't really understand why you should add the subview to the superview. Why not add it just to self.view
I may not be able to explain why there is no superview but try either adding the controller view to self.view or
[[[[UIApplication sharedApplication] delegate] window] addSubview:yourview];
This will render the view on top of everything.
Okay so I feel like there's something obvious I'm missing in this question. I've used makeFirstResponder throughout my code to move from textField 1 to 2, 2 to 3, etc. That seems to work as I want it to, yet when the new view is loaded, I want the cursor to be in textField1, and yet the following code does not place the cursor in textField1 upon load.
- (void) awakeFromNib{
[[[self view] window] makeFirstResponder:textField1];
}
I also tried setInitialFirstResponder, and that didn't have any effect either (I don't even think that would be right.) So, is it because it is in the awakeFromNib method? Can anyone tell me what I'm missing? Thanks in advance.
EDIT - My solution was differed slightly from the accepted answer so I thought I'd post my implementation. Because the view I wanted to set the first responder for was a subview added later (think the second screen of an application wizard), I simply added a setCursorToFirstTextField method:
- (void) setCursorToFirstTextField {
[[[self view] window] makeFirstResponder:textField1];
}
And made sure to call it after I had added the subview to the custom view on the original window.
Yes, you're right about the problem being the location of the method in awakeFromNib. If you log [self.view window] in your awakeFromNib, you'll see that it's NULL. I don't know how exactly you have things set up, but I'm guessing (if this relates to your WizardController question) that you're doing an alloc initWithNibName:bundle: in another class to create your view controller and then adding that controller's view to the view hierarchy. If you throw some logs in there, it will show you that awakeFromNib in the controller class is called after the alloc init, but before the view is added as a subview, so there is no window at that time. The way I got around this problem was to create a setup method in the view controller class (with the makeFirstResponder code in it), and call it from the class where you create the controller after you add it as a subview.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.wizard = [[WizardController alloc] initWithNibName:#"WizardController" bundle:nil];
[self.window.contentView addSubview:wizard.view];
[self.wizard doSetup];
}
I have a view controller that contains a UITableView. When the view controller gets pushed onto the stack, the table view delegate methods get called and it populates the table.
Then I push another view controller onto the one that contains the table view. What I would like to make happen is that - when the second view controller gets popped and I return to the previous view controller, those uitableview delegate methods get called again (so as to repopulate the table).
In other words, how do you repopulate a uitableview when popping to a view controller.
Thanks
In viewDidLoad or viewDidUnload, viewWillAppear, viewWillDisappear (whichever of these is right for your situation) you can put [myTable reloadData];:
// If you can include some code it would help as I am a bit uncertain
// about exactly what you are trying to do from the question but
// you should use whichever of these is correct for project:
- (void)viewDidLoad {
[super viewDidLoad];
[myTable reloadData];
}
- (void)viewDidUnload {
[myTable reloadData];
}
- (void)viewWillAppear {
[super viewWillAppear];
[myTable reloadData];
}
- (void)viewWillDisappear {
[super viewWillDisappear];
[myTable reloadData];
}
What you should do is add a [self.tableView reloadData] (or whatever your table variable is) call inside the viewWillAppear method of its view controller. This will cause the table view to be reloaded both when being pushed (as it does now) and when other view controllers are popped to reveal it.
I have view controller, into the view i have put a table view, and a search bar into the table's header... the search bar is not showing up, just the empty table view.
Do i need to do something additional? I'm pretty sure its to do with the view outlet of the UIViewController, set to View...
Thanks
For anyone else who may be landing on this question, I had a very similar situation where a UITableViewController with a UISearchBar added to it wasn't displaying. If you find yourself in this situation, double check that you are actually calling:
initWithNibName:#"MyNibName" bundle:nil
to init your view controller instead of the common Table View init of:
initWithStyle:UITableViewStylePlain
I was foolishly adding the search bar to the Nib, and then loading it with the style init (which skips the Nib entirely and loads the table view from scratch)
try setting the tableHeaderView of your tableView to your searchBar.
self.tableView.tableHeaderView = searchBar;
if you are using IB, be sure to connect the outlets so that it gets referenced.
Try this,l it worked for me:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.tableView.tableHeaderView = _searchBar;
[_searchBar becomeFirstResponder];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[_searchBar resignFirstResponder];
self.tableView.tableHeaderView = _searchBar;
}
-(void) scrollViewDidScroll:(UIScrollView *)scrollView
{
searchBar.frame = CGRectMake(0,MAX(0,scrollView.contentOffset.y),320,44);
}
If you set your view controller as a part of tabbar controller, besides "Class" property in IB set the "NIB name" property. It takes me several hours to figure it out.
Fixed using a UISearchBar with controller.