I’ve set up a LibraryDataController class that gets data from an sqlite database. This is its .h file:
#import <Foundation/Foundation.h>
#import <sqlite3.h>
@interface LibraryDataController : NSObject{
sqlite3 *database;
}
@property (nonatomic) NSMutableArray *masterPhotoList;
-(NSInteger)listCount;
-(NSString*)objectInListAtIndex:(NSUInteger)index;
-(void)createEditableCopyOfDatabaseIfNeeded;
-(void)initializeDefaultList;
-(void)closeDatabase;
@end
I also have a library view that has a LibraryDataController member:
#import <UIKit/UIKit.h>
@class LibraryDataController;
@interface LibraryViewController : UICollectionViewController
@property (nonatomic, strong) LibraryDataController *dataController;
@end
My problem occurs on the app startup where I load information from the sqlite database into a data controller (The init function does this successfully). Then I try to assign the database to the library view. The library view is the second view on a tab bar, and the tab bar controller is the root view.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
LibraryViewController *libraryView = [[tabController viewControllers] objectAtIndex:1];
LibraryDataController *aDataController = [[LibraryDataController alloc] init];
libraryView.dataController = aDataController;
return YES;
}
The error comes from the libraryView.dataController = aDataController; line. Any ideas about what my problem is? I’m thinking it may have to do with the UICollectionView as I am very new to it. This code is almost identical to code I used successfully with a UITableView and I was under the impression the two views were very similar. Thanks for your help.
The error message
shows that
libraryView(which is the second view controller of the tab bar controller) is an instance ofUICollectionViewController, and notLibraryViewController, as you expected.The solution is to set the “Custom Class” of the view controller in the storyboard file to “LibraryViewController” (using the “Identity inspector).