zoukankan      html  css  js  c++  java
  • 学习笔记:Tab Bar 控件使用详解

    注意这里是:Tab Bar 不是Tab Bar Controller. Tab bar是继承UIView,所以可以添加到ViewController里。是View就可以add到另一个View上去。Tab Bar Controller是新建View视图。

    XX.h 里需要定义UITabBar,并且要引用协议 UITabBarDelegate.

    @interface LoginViewController :UIViewController<UITabBarDelegate>

    {

        UITabBar *tabbar;

    }

    @property (nonatomic, retain) UITabBar *tabbar;

    XX.m

    @synthesize tabbar;

    - (void)viewDidLoad

    {

        //加载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;//指定其代理方法,不然方法不起作用

        [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];

    }

  • 相关阅读:
    Codeforces Round #555 (Div. 3) A B C1(很水的题目)
    蓝桥杯国赛之阶乘位数
    POJ-1258 Agri-Net(最小生成树)
    昂贵的聘礼(枚举区间+最短路)
    地斗主(矩阵快速幂)
    救救兔子(二分)
    shell编程之sed编辑器&gawk程序
    typedef&nbsp;struct与struct的区别
    iOS内存管理编程指南
    Object&nbsp;c&nbsp;基础知识
  • 原文地址:https://www.cnblogs.com/langtianya/p/3976152.html
Copyright © 2011-2022 走看看