Note: The tab bar is not the tab bar controller. The tab bar inherits the uiview, so you can add it to the viewcontroller. You can add the view to another view. The tab bar controller is used to create a view.
Uitabbar must be defined in XX. h and the uitabbardelegate protocol must be referenced.
@ Interface loginviewcontroller: uiviewcontroller <uitabbardelegate>
{
Uitabbar * tabbar;
}
@ Property (nonatomic, retain) uitabbar * tabbar;
XX. m
@ Synthesize tabbar;
-(Void) viewdidload
{
// Load the tab bar
Cgrect footframe = cgrectmake (0,420,320, 60 );
Tabbar = [[uitabbar alloc] initwithframe: footframe];
Uitabbaritem * Item1 = [[uitabbaritem alloc] initwithtabbarsystemitem: 1 Tag: 0];
Uitabbaritem * item2 = [[uitabbaritem alloc] initwithtabbarsystemitem: 2 Tag: 1];
Nsarray * items = [[nsarray alloc] initwithobjects: Item1, item2, nil];
[Tabbar setitems: Items animated: Yes];
[Item1 release];
[Item2 release];
[Items release];
[Self. View addsubview: tabbar];
Tabbar. Delegate = self; // specify its proxy method. Otherwise, the method does not work.
[Tabbar release];
}
-(Void) tabbar :( uitabbar *) tabbar didselectitem :( uitabbaritem *) item
{
Nslog (@ "selected is % d", item. Tag );
Nsstring * MSG = [[nsstring alloc] initwithformat: @ "selected is % d", item. Tag];
Uialertview * Alert = [[uialertview alloc] initwithtitle: @ "a" message: MSG delegate: Self cancelbuttontitle: @ "OK" otherbuttontitles: nil, nil];
[Alert show];
[MSG release];
[Alert release];
}
Learning notes: Use of the tab bar Control