UITabBarController和UITabBarControllerDelegate

本文详细介绍了iOS中UITabBarController的使用方法及属性说明,包括如何设置和获取当前选中的视图控制器、更多导航控制器的创建与使用等。此外还探讨了自定义控制器的功能及其委托方法的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

NS_CLASS_AVAILABLE_IOS(2_0) @interface UITabBarController : UIViewController <UITabBarDelegate, NSCoding> 

@property(nonatomic,copy) NSArray *viewControllers;

// If the number of view controllers is greater than the number displayable by a tab bar, 
// a "More" navigation controller will automatically be shown.
// The "More" navigation controller will not be returned by -viewControllers, 
// but it may be returned by -selectedViewController.
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated;

// This may return the "More" navigation controller if it exists.
//The view controller associated with the currently selected tab item
@property(nonatomic,assign) UIViewController *selectedViewController; 

//The index of the view controller associated with the currently selected tab item.
@property(nonatomic) NSUInteger selectedIndex;

// Returns the "More" navigation controller, creating it if it does not already exist.
@property(nonatomic,readonly) UINavigationController *moreNavigationController; 

// If non-nil, then the "More" view will include an "Edit" button that displays 
// customization UI for the specified controllers. By default, all view controllers are customizable.
@property(nonatomic,copy) NSArray *customizableViewControllers;

// Provided for -[UIActionSheet showFromTabBar:]. 
// Attempting to modify the contents of the tab bar directly will throw an exception.
@property(nonatomic,readonly) UITabBar *tabBar NS_AVAILABLE_IOS(3_0); 

@property(nonatomic,assign) id<UITabBarControllerDelegate> delegate;

@end

@protocol UITabBarControllerDelegate <NSObject>
@optional

//Asks the delegate whether the specified view controller should be made active.
- (BOOL)tabBarController:(UITabBarController *)tabBarController 
                          shouldSelectViewController:(UIViewController *)viewController NS_AVAILABLE_IOS(3_0);

//Tells the delegate that the user selected an item in the tab bar.
- (void)tabBarController:(UITabBarController *)tabBarController 
                          didSelectViewController:(UIViewController *)viewController;

//Tells the delegate that the tab bar customization sheet is about to be displayed.
- (void)tabBarController:(UITabBarController *)tabBarController 
                          willBeginCustomizingViewControllers:(NSArray *)viewControllers NS_AVAILABLE_IOS(3_0);

//Tells the delegate that the tab bar customization sheet is about to be dismissed.
- (void)tabBarController:(UITabBarController *)tabBarController 
                          willEndCustomizingViewControllers:(NSArray *)viewControllers 
                          changed:(BOOL)changed NS_AVAILABLE_IOS(3_0);

//Tells the delegate that the tab bar customization sheet was dismissed.
- (void)tabBarController:(UITabBarController *)tabBarController 
                          didEndCustomizingViewControllers:(NSArray *)viewControllers
                          changed:(BOOL)changed;
@end

@interface UIViewController (UITabBarControllerItem)

// Automatically created lazily with the view controller's title if it's not set explicitly.
@property(nonatomic,retain) UITabBarItem *tabBarItem; 

// If the view controller has a tab bar controller as its ancestor, return it. Returns nil otherwise.
@property(nonatomic,readonly,retain) UITabBarController *tabBarController; 

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值