Multiple collection view on one view controller - objective-c

I have 4 collection view on one view controller and different data has to be fetched from api for every view controller.
The data has been fetched one by one but how to fetch data for all collection view at the same time.
As i know i can use CollectionView DataSource and delegate methods for once and i have to implement methods for 4 collection view in one but it app crashes giving error
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[HomeScreenViewController collectionView:cellForItemAtIndexPath:]: unrecognized selector sent to instance.
Can anyone tell me how to solve this problem??

I would strongly suggest that you use a separate UICollectionViewController for each of your collection views. This can be achieved easily in the InterfaceBuilder via ContainerViews.
Coordinating all four CollectionViews in one View Controller is possible - but ugly.

Related

Error in simulator when try run an app

I created app with using storyboards. My app has a table, some buttons and labels.
When I try to run my app simulator generates an error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x719de00'
UIViewController tableView:numberOfRowsInSection: means that I can't use "numberOfRowsInSection" with "UIViewController"?
I tried to use "UITableViewController" instead but with this controller I can't locate the buttons and labels in right place for me.
What I do wrong?
Thanks.
Once you Add the UITableView and set Datasource and Delegate, we must use some UITableview Delegate Methods. such as NumberOfRowsInSection, NumberOfSection, and so on.
Kindly Use the Essential Delegate Methods or Remove the UItableView.
You need to delegate the UITableView to the UIViewController, open the Connections inspector and drag the "delegate" and "dataSource" entries to the main view controller on the storyboard.

UIViewControllerHierarchyInconsistency View Controller exception

I'm trying to change the detail view in a splitViewController, i have the UIViewControllerHierarchyInconsistency exception when i do
self.detailView.view=view.view;
I've controlled if there are other viewControllers in xib files and i also used method removeFromParentViewController, but i've the same exception.
The error is only in iOS 6 but not in iOS 5, in iPad simulator.
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'A view can only be associated with at most one view controller at a time! this is the error, view.view is the view i want to load in the splitViewController, there is no other code, i do only the change of the view in the split, i used removefromparentviewcontroller because i want to remove the association to the viewController to remove the exception
Is your splitViewController an instance of UISplitViewController?
http://developer.apple.com/library/ios/#documentation/uikit/reference/UISplitViewController_class/Reference/Reference.html
If so, you're doing something fundamentally wrong. The UISplitViewController is simply a container for two view controllers, a master view controller and a detail view controller. It is then up to your view controller to decide how to deal with interactions and such. removeFromParentViewController is only used in View Controller Containment, and as such doesn't seem applicable here.
Read the documentation in the link above to see if it meets your needs, but if I understand, you need to set your view controllers in the split view, not your views.
To do you, you need to do:
// Assume this is initialised correctly
UISplitViewController* splitViewController = [UISplitViewController alloc] init...];
// Assign the two view controller you want to be used in the split view controller
splitViewController.viewControllers = #[masterViewController, detailViewController];
If this isn't applicable, then please provide your code so that a correct solution can be made. Your descriptions have been rather vague as to what you're actually doing.

Setting an identifier for an Xcode Storyboard Segue in a UITabBarController, and getting a pointer to its view controller

This is my first app using storyboards/segues, and I'm pretty sure the answer to this is easy, but I'll be as thorough as possible in describing my issue.
I am making a simple app which has a Tab Bar Controller scene and two View Controllers.
My app launches by being sent a URL from another app. The application:openURL:sourceApplication:annotation: method in the app delegate performs some work to determine
which tab to display first, and
what information to display on it.
My goal is to use the performSegueWithIdentifier method (I'm open to alternatives though) from within the AppDelegate to select the tab, and also find a way to send a method to the instance of the view controller created by the storyboard.
Issue #1 is that I can't set an identifier. When I select the tab "relationship" there are no choices available in the Attributes Inspector (it says "Not Applicable"). How do I set a name for this segue? Can I? Or is there some rule under which UITabBarController segues can't be trigger programmatically?
Issue #2 is that I can't find a way to have a pointer to the view controller. Pre-Storyboard I would alloc and init a new view controller and then set it up, but here if I do that, it does not get displayed when my app launches (I think this is because Storyboard is displaying a different instance of the same view controller.)
I know this post is long, but I feel like I'm missing something simple. What is it?
Sounds like you need to have your AppDelegate set the entry point to your storybard.

iOS 5 viewWillAppear not being called when popping a NavigationController

I am learning to develop iPhone applications using iOS 5.
I am trying to create a contact list of sorts (to learn about Core Data).
I have a UITableView embedded in a UINavigationController (I have done this through Editor -> Embed In -> Navigation Controller).
At the end of my saveContact action I have the line:
[self.navigationController popViewControllerAnimated:YES];
To move from the contact creation form to the UITableView which lists all the contacts. The code that fetches the contacts is in viewWillAppear.
Problem is that when I pop the contact creation form the new contact does not show on the list.
I have found in Apple's documentation that I should add the UINavigationControllerDelegate to my UITableViewController, but no success.
Any suggestions?
You need to implement the navigationController:willShowViewController:animated: method of the UINavigationController protocol in your UITableViewController and set the delegate of the navigation controller the table view controller. In you implementation of the method, check if the view that will be shown is equal to your view, and if it is then fetch the results.
If you really want to integrate Core Data with a table view, I would recommend looking into NSFetchedResultsController. It simplifies handling updates to the backing data store, so if you later added background syncing functionality, the background thread could continuously update the store, and the NSFetchedResultsController could then handle updating the table for you. It would also make your current example easier, as all you'd have to do is send save: to Core Data and then the results controller would start updating your table, without using a viewWillAppear: method

Understanding the UIViewController lifecycle and passing of variables in iOS in Storyboards

I was trying to understand what's going on in a UIViewController->UIView when loaded from Interface Builder or Storyboards.
I start wondering about how things works in background when facing the most commons of problem, which is passing parameters between controllers.
In a Storyboards using the navigation controller I have a table view loaded by CoreData element, and the single element is passed as NSManagedObjectID onto the next controller via #property in the segue method for displaying a detail view.
On the receiving controller I am doing a check of the existence and reconstruct the full object when needed.
At this point, comes the question, where's the best place to put and handle this logic ?
I come from a Java EE background, where the controller is called a servlet, and a servlet for performance reason may be initialized once and shared by many users (by means of Thread Pool) and therefore is discouraged (dangerous is more appropriate) to have instance variable.
Just because a #property is an instance variable I don't want to fall in the same mechanism, my UIViewController is instantiated once and the CoreData object stays the same in case of view controller.
On iOS, each view controller manages a single view and its subviews. Even if you used a UISplitViewController to put two identical view controllers on the screen at once, they would be two separate instances of the view controller class, and I believe storyboards instantiate a new view controller for each segue performed (though I could be wrong). Thus it's not only perfectly safe to use properties—it's expected practice.