簡體   English   中英

iOS UITabbar無法正常工作?

[英]iOS UITabbar is not working?

我將一個UITabBar拖放到UIViewController (xib)中,並創建了這樣的對象

@property (strong, nonatomic) IBOutlet UITabBar *tabbar;

我添加了UITabBarDelegate並且didSelectViewController代碼是:

-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    NSLog(@"Selected INDEX OF TAB-BAR ==> %i", tabBarController.selectedIndex);

    if (tabBarController.selectedIndex == 3) {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"APICON" message:@"test" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];
    }
}

但是,當我單擊UITabBar項警報時,為什么不出現?

xib或以編程方式為您設置委托xib ,如下所示

tabbar.delegate=self;

並將IBOutlet UITabBar *tabbar替換為IBOutlet UITabBarController *tabbar

我將UITabBarController拖到您的xib中,這將是您的主視圖控制器。

您將需要在應用程序委托中為UITabBarController創建一個插座,然后在xib中將該插座連接到選項卡欄控制器。

之后,您可以為您的應用添加其他標簽。

您還可以創建作為選項卡式應用程序的Xcode項目,並查看其代碼以獲取其他幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM