I want to use a login scene as the initial view controller and to connect it to a tab view controller. I keep receiving the following error message:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController tabBar]: unrecognized selector sent to instance 0x7fe85a560fd0'
// LogInViewController.h
#import <UIKit/UIKit.h>
@interface LogInViewController : UIViewController <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *txtUsername;
@property (weak, nonatomic) IBOutlet UITextField *txtPassword;
- (IBAction)sigininClicked:(id)sender;
- (IBAction)backgroundTap:(id)sender;
@end
// AppDelegate.m
//
#import "AppDelegate.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Assign tab bar item with titles
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
UITabBarItem *tabBarItem4 = [tabBar.items objectAtIndex:3];
tabBarItem1.title = @"Trucks";
tabBarItem2.title = @"Dashboard";
tabBarItem3.title = @"Map";
tabBarItem4.title = @"Settings";
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"iu.png"]
withFinishedUnselectedImage:[UIImage imageNamed:@"iu.png"]];
[tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"dashboard.png"]
withFinishedUnselectedImage:[UIImage imageNamed:@"dashboard.png"]];
[tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"globe.png"]
withFinishedUnselectedImage:[UIImage imageNamed:@"globe.png"]];
[tabBarItem4 setFinishedSelectedImage:[UIImage imageNamed:@"settings.png"]
withFinishedUnselectedImage:[UIImage imageNamed:@"settings.png"]];
return YES;
}
I'm not an expert at ios, but here is how I did it programmatically recently (without storyboards) in my app. This is the code extracted from my appdelegate but it should work for your purpose as well.
In the .h file:
In the .m file:
EDIT:
Within my FirstViewController and SecondViewController .m files:
Hope this helps.