I have a UISplitview
controller (with a master and detail view). So, when the detailview
loads the viewDidLoad
calls a function named [self animateToPosition];
with the following code:
-(void*)animateToPosition
{
NSLog(@"Called Function");
[worldV animateToPosition:MaplyCoordinateMakeWithDegrees(-122.4192, 37.7793) time:1.0];
[self.view setNeedsDisplay];
return 0;
}
Now, when this is first run, my globeViewC
correctly animates to the position passed in (worldV
is initialized and created an all in viewDidLoad of detailviewController
also "Called Function" is printed in the log.
However, I have a view controller and in the didSelectRowAtIndexPath
I have the following code (in the file masterViewController.m
)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([[testArray objectAtIndex:indexPath.row]isEqualToString:@"Menu1"]) {
DetailViewController *test=[[DetailViewController alloc]init];
[self addChildViewController:test];
[self.view addSubview:test.view];
[test didMoveToParentViewController:self];
[test animateToPosition];
}
}
When I select the cell called menu1
, "Called function" DOES display in the NSLog
, but the animation that occurred when the view was first loaded doesn't anymore. I'm wondering if I must somehow reload the detailviewcontroller
or initialize it again (but I tried initializing it again and that didn't work)
Would like if someone could see this and help me get this working.
It would be helpful if you could show more, especially how you alloc
and init
your worldV
and what you have in your viewDidLoad
.
Normally you don't create a new DetailViewController for SplitView setup.
Instead of creating a new DetailViewController, try to grab a hold of the existing detail view controller by creating a property:
@property(strong, nonatomic) DetailViewController *detailViewController;
and:
self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
First thing to test here is whether your worldV
is nil
. A simple NSLog in animateToPosition
would reveal the answer.
And whenever you need to call that method, do:
[self.detailViewController animateToPosition];
To animate from one coordinate to another with time, you may need to change your animateToPosition
method to:
-(void)animateToPosition:(MaplyCoordinate)coordinates time:(CGFloat)time
Consult whether or not your MaplyCoordinate
is an object, which I doubt.
So, to sum up, in your tableview's viewDidLoad
, get a hold of the detail view controller.
When didSelectRow
gets called, use the new method suggested and pass the coordinate and time this way:
[self.detailViewController animateToPosition:coordinates time:1.0];
Hope this helps.