I have declared a UITabBarController in my AppDelegate.m file. I have two viewcontrollers in this UITabBarController.
In each of the views, lets call them view1 and view2, i have the following code:
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self)
{
UITabBarItem *tbi = self.tabBarItem;
tbi.title = @"title";
UIImage *i = [UIImage imageNamed:@"picture.png"];
tbi.image = i;
tbi.tag = 0;
}
This makes me able to freely navigate between two viewcontrollers.
Now, to the question:
I want to have an event when i click each of the tabs. I have googled for 4 hours now and tried a lot of things. I'm close to going insane.
Where do i put what kind of code to be able to execute something when i click each tab?
Please dont say " you need to implement UITabBarDelegate and then use -void(didselectitem) " without explaining exactly how :)
EDIT: My AppDelegate.h file:
#import <UIKit/UIKit.h>
@interface PETTAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate, UITabBarDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
My AppDelegate.m file:
@implementation PETTAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
NSBundle *appBundle = [NSBundle mainBundle];
PETTSoundBoardPage *sbP = [[PETTSoundBoardPage alloc]initWithNibName:@"PETTSoundBoardPage" bundle:appBundle];
PETTNPage * nP = [[PETTNPage alloc]initWithNibName:@"PETTNPage" bundle:appBundle];
UITabBarController *tBC = [[UITabBarController alloc]init];
tBC.tabBarController.delegate = self;
tBC.viewControllers = @[sbP,nP];
self.window.rootViewController = tBC;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
sbP and nP file (almost identical code except for title and picture):
-(instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if(self)
{
UITabBarItem *tbi = self.tabBarItem;
tbi.title = @"Soundboard";
UIImage *i = [UIImage imageNamed:@"picture.png"];
tbi.image = i;
tbi.tag = 0;