5
votes

Can't figure out what's going on.

I'm building an iPhone-app that uses a scroll view with paging. The scroll view contains several views, whose view controllers are loaded up from the storyboard by calling:

[self.storyboard instantiateViewControllerWithIdentifier:@"identifier"];

I add the view controllers to a mutable array and add their views to the scroll view as subviews. After appearing on screen, the view controllers are deallocated, so target-actions don't work anymore.

When I enabled Zombie Objects, the debugger wrote this on sending an action to the controller:

*** -[StreamingViewController performSelector:withObject:withObject:]: message sent to deallocated instance 0x914f0e0

I really tried to fix this but without success, so every help is much appreciated.

Some more code:

StreamingViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Streaming View Controller"];

[self.pageControllers addObject:controller]; // adding view controller to mutable array

controller.view.frame = self.scrollView.frame;
[self.scrollView addSubview:controller.view];
1
How is pageControllers declared? - Mark
pageControllers is declared as a private @property - user1564913

1 Answers

2
votes

If you are using ARC things drop out generally when you no longer have a valid pointer to something. So in your case your view controller goes out of scope and is released. The view is still retained as it is being held by self.scrollView. Adding the view controller to an array would fix that but only if the array has been instantiated correctly. Poperties are not instantiated automatically. Using the property also does not instantiate it for you unless you override the accessor. Because of the nature of Cocoa you won't get any errors or messages by trying to add an object to a nil property as it is completely valid code.

Check how you are creating pageControllers and make sure you are instantiating it correctly before using it.

eg.self.pageControllers = [[NSMutableArray alloc] init];