UITableView ignoring method call only on iPhone 5 - objective-c

This seems strange, and maybe I don't have the issue fully nailed, but I am perplexed.
In my app, I present a UITableView modally in a VC and have created a custom init method to additionally send an index path for where the table should scroll to.
in ViewDidLoad, the following call is executed correctly on iPhone4S and earlier, but ignored on iPhone5:
[table scrollToRowAtIndexPath:iP atScrollPosition:UITableViewScrollPositionTop animated:NO];
Any suggestions? Have I made any false assumptions?

Related

Getting viewDidLoad to be called when using popViewControllerAnimated

I'm using a UINavigationController to navigate between classes. When I press a button on the first view to send me to the second one, everythin works fine. But when I wan't to return from the second, to the first view, the viewDidLoad method isn't being called, and I really need that to happen.
According to this post, I should somehow set my view to nil but I'm not sure where or how to do that. This is the code that I'm using to return to the first view:
NewSongController *nsContr = [[NewSongController alloc] initWithNibName:#"mNSController" bundle:nil];
[self.navigationController popViewControllerAnimated:YES];
[nsContr release];
Your code is not correct.
You don't need to instantiate your first controller in order to pop to it. It already exists.
viewDidLoad will only run when you load the viewController for the first time (i.e. when you push to it). When you push to other controllers they are put onto a stack (imagine a stack of cards). When you push another card onto the stack the cards beneath it are already there.
When you pop it is like removing a card from the stack. But the card underneath is already there so it doesn't need to load again. All it does is run viewWillAppear.
All you need to do to pop back is...
[self.navigationController popViewControllerAnimated:YES];
That's it.
Remove the stuff about NewSongController (if that is what you are trying to go back to).
Then in the NewSongController function - (void)viewWillAppear:animated; put the code you want to run when you get back to it.
Hope that helps.
Your first view is loaded and is pushed onto the navigation stack. Dont try to mess with whats on the stack without fully understanding how setting the view to nil will affect the behavior.
Whatever you do on viewDidLoad, doing it in viewWillAppear or viewDidAppear will give you the result you want.
The viewDidLoad wouldn't appear because it already exists in the navigation stack. Since you are going back in the stack you would want to have the code that you want to trigger in viewWillAppear or viewDidAppear which is executed when popping from one viewcontroller to the one below it.

After segue ViewDidLoad is called but ViewWillAppear and ViewDidAppear is not being called

I have created a segue in storyboard named "CreateGame".And called it with my viewController to Load CreateGameViewController using[self performSegueWithIdentifier:#"CreateGame" sender:nil] but is is not working. it was working some time ago but suddenly it is not working.
I have taken a look of my code. My
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSLog(#"Segue");
}
is being executed each time when i call [self performSegueWithIdentifier:#"CreateGame" sender:nil]and then CreateGameViewController's"viewDidLoad" is being executed (conformed by using NSLog(); statement) . but CreateGameViewController's ViewWillApper is not being called.
i am using NavigationController So type of segue is 'Push'. some times segue works or sometimes not. Please help me out.
you are doing something in your CreateGameViewController's "viewDidLoad" (may be some looping or some recursion function calling without end) . That would have prevent the screen appears. it would be more helpful if you can provide the code of CreateGameViewController's "viewDidLoad"

Why doesn't performSegueWithIdentifier work inside viewDidLoad?

I'm trying to trigger a storyboard segue as soon as viewDidLoad is called on a view controller. The segue has an identifier attached, and works fine when called from inside a method thats linked to a button or other control. But it doesn't work inside of viewDidLoad. It just silently fails. Is there some rule about segue's being ignored in viewDidLoad?
I've tried both this:
[self performSegueWithIdentifier: #"mySegue"
sender: self];
and this:
[self dismissViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:#"mySegue" sender:self];
}];
Neither work.
You can not dismiss a view controller that isn't presented yet. didLoad has purely memory management functions, you can use it as (part of a) constructor.
What may work, is to start a segue in viewDidAppear, however I would suggest to start with the view you want at the first time.
Most likely reason could be that the OS ignores second screen transition call while one is in progress. In your ViewDidLoad, the view transition (of the current view) is still not complete. You are asking another transition before it completes and the OS ignores it. It must be the reason that the segue works when called from a different function. Try calling inside ViewDidAppear (or after a time delay)

iPad SplitView Controller crashes when after the DetailView loads when trying to access the master controller again

I'm porting a fairly simple iPhone Navigation based app to a Split View iPad app. I have two nested levels of navigation on the Master view. The user picks a value from the first table and it loads the 2nd table. Selecting a value on the second table loads the Detail item for the detail view. I've (finally) gotten that part working.
When I try to pull up the Master view again, though, whether using the popover menu button in portrait or just navigating back to it and clicking on a record in landscape view, it crashes with a GDB: Program received signal: "EXC_BAD_ACCESS" error. I can't find anyplace in the code to step into to identify the problem.
I'm following the SplitView template fairly closely. I'm only really getting off the beaten track by adding that 2nd TableViewController. My RootViewController loads the 2nd TableViewController.
Here's the code:
First, in RootViewController.m I'm loading the 2nd TableView when an item is selected on the 1st (in didSelectRowAtIndexPath):
RequestsTableViewController *requestsTableViewController=[[RequestsTableViewController alloc] initWithNibName:#"RequestsTableViewController" bundle:nil];
requestsTableViewController.selectedDepartmentID = self.selectedDepartmentID;
[self.navigationController pushViewController:requestsTableViewController animated:YES];
[requestsTableViewController release];
Then, in the 2nd TableViewController, RequestsTableViewController, I load the detail item based on its selection in didSelectRowAtIndexPath:
TrackerSplitViewAppDelegate *appDelegate = (TrackerSplitViewAppDelegate *)[[UIApplication sharedApplication] delegate];
Request *aRequest = [appDelegate.requests objectAtIndex:indexPath.row];
appDelegate.detailViewController.thisRequest = aRequest;
appDelegate.detailViewController.detailItem = [NSString stringWithFormat:#"Row %d", indexPath.row];
[appDelegate release];
The app loads and sets my values and everything is working fine. I can navigate between the two TableViewControllers just fine with the auto-generated navigation as long as I don't click on a detail. Once I click on a detail and it's loaded, though, I crash the app if I try to re-access the MasterView.
I did nothing to the nib files to wire this navigation up, it all worked ported from the iPhone app (other than this crash). I can't find any examples with multiple master views to see where my wire up is different. I suspect I have to tweak something in the interface builder or something, but as I can't tell exactly where it's crashing, I'm having a hard time getting started. Or do I just need to push the original view back on to the stack programmatically after a detail has been selected? That seems ham-fisted.
[appDelegate release];
You should not release the appDelegate unless you've retained it. And you haven't done this. So get rid of this line.

Odd behavior when showing UIPopoverController

In my iPad app, I save the state (visible/not visible) of a popover. So, during the launch of the app I initialize the UIPopoverController and tell it to show itself by using presentPopoverFromBarButtonItem:permittedArrowDirections:animated:. For the first argument (UIBarButtonItem), I use self.navigationItem.rightBarButtonItem. However, the popover keeps showing up on the left side of the screen (and not underneath the targeted button).
After the app is launched, the behavior is as expected. Any suggestions how to solve this?
For your information, I initialize the rightBarButtonItem and assign it to the navigationItem in the viewDidLoad method and before asking the popover to present itself. I have tried to call the popover in viewWillAppear and viewDidLoad, but the effect is the same.
My best alternative is to use presentPopoverFromRect:inView:permittedArrowDirections:animated: instead and "guess" the position depending on the orientation of the device.
Update: when I rotate the iPad, the popover does jump to the correct position. It seems that the barButtonItem's position is only determined at the last minute and after I ask my popover to present itself.
In situations like these where timing appears to be important I found that the trick of postponing an action until the next iteration of the run loop helps. If developing for iOS 4.0+, this can be easily achieved with GDC:
// call from viewDidAppear:
dispatch_async(dispatch_get_main_queue(), ^{
// call presentPopoverFromBarButtonItem:permittedArrowDirections:animated: here
});