【发布时间】:2013-05-31 08:11:20
【问题描述】:
我正在尝试在我的应用程序的多个视图控制器中包含一个标签栏,上面有 4-5 个标签栏项目,并将用作在视图(地图、关于、收藏夹等)之间跳转的菜单。
我在 Storyboard 上创建了一个 UITabBar 项目并设置了它的 Bar 项目的标签。因为相同的选项卡栏将用于其他几个视图控制器(Main、View2、View3 等),所以我决定创建一个扩展 UITabBar 的类。这将帮助我以后自定义栏。 Storyboard 中的 UITabBar 对象现在是此类 (BottomTabBar) 的对象。
我的问题是,如何检测何时点击了条形项?
另外,由于我对 TabBar 不熟悉,如果您有任何通用指南或提示可以在开发过程中帮助我,请与我分享。
BottomTabBar.h
#import <UIKit/UIKit.h>
@interface BottomTabBar : UITabBar <UITabBarDelegate>
@end
BottomTabBar.m
#import "BottomTabBar.h"
@implementation BottomTabBar
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.delegate = self;
}
return self;
}
- (void) tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
NSLog(@"Tabbed!");
}
@end
MainViewController.h
#import <UIKit/UIKit.h>
#import "BottomTabBar.h"
@interface MainViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>{
AppDelegate *appDelegate;
NSArray *searchResults;
}
@property (strong, nonatomic) IBOutlet UIScrollView *slideshow;
@property (strong, nonatomic) IBOutlet UIPageControl *scroll;
@property (strong, nonatomic) IBOutlet BottomTabBar *bottomBar;
@end
【问题讨论】:
标签: ios objective-c