UINavigationController back button issue - xcode

My Application have navigation controller and table views. When the back button is clicked and the view is popped out from controller stack, i noticed that the table events are not executed (eg: cellForRowIndexPath). Is there anyway that these events are execueted when view is popped out.
This is the code i use for pushing the view into controller stack.
MyViewController *obj = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
[self.navigationController pushViewController:obj animated:YES];
[obj release];
Regards
Sandy

You can use the ViewWillAppear and ViewWillDisappear methods.
what you want to do is put a call to
[theTable reloadData];
which initiates all of the calls that you wanted.
This call should be placed where you want the table to reload - either on appear or disappear.
Good Luck !

Related

Update a UITableview from a different view when both views visible at once

Looking at my iPad app, I have several containerviews. Containerviews enable me to show all four iphone views on a single iPad screen simultaneously. One view, called TrackingViewController, has a UITableView on it (called table) that I want to refresh from a button on a second view controller (MainViewController) which is also visible on the same iPad screen. I call the code
TrackingViewController *trackView = [[TrackingViewController alloc] init];
[trackView.view setNeedsDisplay];
[trackView.table reloadData];
at the end of the IBAction for the button in MainViewController, the data transfers perfectly, but the table itself on TrackingViewController does not visually update to show this data.
If I then manually initiate a completely different modal view controller and dismiss it on TrackingViewController when the app is running on iPad then the data shows up. How do I make the view or data on TrackingViewController automatically update visually when the button is pressed on MainViewController?
iPad Simulator may help.
I also dont understand your question..
The only thing I see is, you want to update two UITableViews but in your code you are only reloading Data of one TableView?!?
[trackView.table reloadData];
[otherTable reloadData];
But I realy dont understand your question....
If your other TableView is in another class, just try something like this...
In TrackingViewController.h:
- (void)refreshMyTable;
In TrackingViewController.m:
- (void)refreshMyTable{
[table reloadData];
}
In your MainViewController.m Action, that should refreshes both Tables:
- (IBAction)theRefreshingAction{
TrackingViewController *trackView = [[TrackingViewController alloc] init];
[trackView refreshMyTable]; //This refreshes Table in trackView
[mainViewTable reloadData]; //This in MainView
}
Ended up using NSNotificationCenter by utilizing the following post:
Calling a function from a different view controller for iphone
In my case, calling a function that only included [table reloadData]; wouldn't work, but calling my performFetch function did (which also called [table reloadData]; at the end of it).

Xcode trigger navigationBar-Back-Button-Action

i have a navigationcontroller with some viewcontrollers and i need to know
how i can trigger the back-button-action on the navigationBar of each viewcontroller.
i have an allert-view and when user presses ok on this alert-view i want the
navigationcontroller to get one step back so i need to trigger the back-button
which appears on each navigationbar on the left side.
Does somebody knows how this works :)
Because if it doenst works i have to implement a navigationcontroller under each viewcontroller to make
[self dismissViewController animated:YES completion:nil]
and i dont want to do that.
You have to pop the front most view controller from the stack.
[self.navigationController popViewControllerAnimated:YES];
You could also use
[self.navigationController popToViewController:someViewController animated:YES];
if you wanted to go directly back to someViewController.

Force aplication to go to previous view without a button xcode

I have created an application that if the page cannot load, it gives an error message. However, after that, it just shows a blank white screen. How can I edit the code so that it will automatically go to the previous view?
Call popViewControllerAnimated:(BOOL)animated method of the UINavigationController if page cannot load.
My guess that what would work for you would be after the alert do something like:
if(butttonIndex == 1){
Previous_View *next=[[Previous_View alloc] initWithNibName:#"Previous_View" bundle:nil];
[self.navigationController pushViewController:next animated:YES];
}
You can do like this after your message:
[self.navigationController popViewControllerAnimated:YES];
or if you want to jump back to the root view:
[self.navigationController popToRootViewControllerAnimated:YES];

UIImageView shifted when I click my back button

I've got a small project with two UIImageView-based nib files.
When the main view loads, it looks correct.
To switch between views, I'm using code like this (for example, this is to go to second view)
-(IBAction) secondClicked:(id)sender {
SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:main animated:NO];
[second release];
}
When the new view is shown, it's shifted sideways about 10% of screen. Using similar code to go back to main results in the main view being shown similarly offset.
I'm in landscape mode, if that makes a difference.
How can I display the views so they're correctly aligned?
Ok it makes sense now that I looked more carefully. Why are you presening a view controller modally when you wish to go back? How did you showed this viewController initially? If it was through a navigation controller you should pop the view
[self.navigationController popViewControllerAnimated:YES];
If it was presented modally you should just dismiss it!
[self dismissViewControllerAnimated:YES];

Tableview not reloading after data change : IOS 5

I need help in following scenario.
I am building an app that displays tableview. If the user tap an entry it goes to the detailed screen. In the detail screen, I have a button to delete this entry. It deletes the entry from the data source and dismiss the modal.
But after dismissing the modal, table view data is not refreshing.
If I go back to parent view controller and then again come back to child screen, it refreshes the count.
I read few similar posts and found the following solution.
[tableview reloadData];
Or
[self.tableView reloadData];
In - (void)viewDidAppear:(BOOL)animated of child screen.
But its not refreshing the table view.
Please help.
For completeness, the full implementation would be:
- (void)viewWillAppear:(BOOL)animated
{
// Do stuff like reload the tableview data...
[self.tableView reloadData];
}
If it's not working you have a problem elsewhere in your code.
If the tableview is in the parent viewcontroller, I suggest that placing reloadData: method at viewWillAppear: of the parent.
(void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}
I'm sure that the method will be called when the detailed viewcontroller dismissed.
Go through this code:
- (void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}

Resources