iOS 导航控制器、标签、表视图的创建方法

导航控制器
//创建导航控制器
BIDRootViewController *pRootVC=[[BIDRootViewController alloc]initWithNibName:nil bundle:nil];
    self.mRootVC=pRootVC;
    [pRootVC release];
 UINavigationController *pNav=[[UINavigationController alloc]initWithRootViewController:self.mRootVC];
    self.window.rootViewController=pNav;
命名
        self.navigationItem.title=@"根视图";
给标题创建一个试图
    UIView *pTitleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 44)];
    [pTitleView setBackgroundColor:[UIColor redColor]];
    self.navigationItem.titleView=pTitleView;
创建一个barItem
UIBarButtonItem *pBar=[[UIBarButtonItem alloc]initWithTitle:@"NextVC" style:UIBarButtonItemStylePlain target:self action:@selector(goToNextVC:)];
    self.navigationItem.rightBarButtonItem=pBar;
barItem调用的方法
- (void)goToNextVC:(id)sender{
    BIDNextViewController *pNextVC=[[BIDNextViewController alloc]initWithNibName:nil bundle:nil];
    [self.navigationController pushViewController:pNextVC animated:YES];
}
tableBar—--标签栏
创建标签栏
BIDViewController *pViewController = [[BIDViewController alloc]initWithNibName:nil bundle:nil];
     UITabBarController *pTapBarVC = [[UITabBarController alloc]init];
    pTapBarVC.viewControllers=[NSArray arrayWithObjects:pViewController, nil];
用系统的资源给标签命名
    self.window.rootViewController = pTapBarVC;
        self.tabBarItem=[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:111];
在右上角添加badgeValue
        self.tabBarItem.badgeValue=@“1";
自定义命名
  self.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"second" image:nil tag:122];
表视图
创建
.h文件中要有:
@property (retain, nonatomic) UITableView *mTableView;
//存储表中的数据
@property (retain, nonatomic) NSArray *mArr;
且遵循UITableViewDataSource,UITableViewDelegate协议。
    
   self.mArr = [UIFont familyNames];
//创建初始化表视图
    self.mTableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    
    UIView *pView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    pView.backgroundColor = [UIColor blueColor];
    
    self.mTableView.tableHeaderView = pView;
    
    //设置页眉高度
    self.mTableView.sectionHeaderHeight = 50;
    //设置委托对象
    self.mTableView.dataSource = self;
    self.mTableView.delegate = self;
   //加到视图当中
    [self.view addSubview:self.mTableView];    
#pragma mark --- tableView  DataSource----
//每个分段中的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.mArr count];
}
//每行的绘制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      static NSString *identifer = @"identfier";
    UITableViewCell *pCell = [tableView dequeueReusableCellWithIdentifier:identifer];
    
    if (nil == pCell)
    {
        pCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifer];
    }
    //获取当前行
    NSUInteger cellRow = [indexPath row];
    //根据行数找到数组中对应下标的数据
    NSString *pTempStr = [self.mArr objectAtIndex:cellRow];
    //设置文本内容
    pCell.textLabel.text = pTempStr;
    //设置文本字体
    pCell.textLabel.font = [UIFont fontWithName:pTempStr size:18];
    pCell.detailTextLabel.text = @“detailText";
//在左侧添加图片
    pCell.imageView.image = [UIImage imageNamed:@"Default-568h@2x"];
    pCell.accessoryType = UITableViewCellAccessoryCheckmark;
    
    return pCell;
}
//创建表头
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"I'm Header_Title";
}
//创建表尾
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    return @"I'm Footer_Title";
}
#pragma mark---table delegate-----
//选中某一行会调用
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUInteger row = [indexPath row];
    NSString *pStr = [NSString stringWithFormat:@"你选中了第%d行",row];
    //模态视图
    UIActionSheet *pActionSheet = [[UIActionSheet alloc]initWithTitle:@"ActionSheet" delegate:self cancelButtonTitle:@"确认" destructiveButtonTitle:pStr otherButtonTitles:nil, nil];
    
    [pActionSheet showInView:self.view];
    //选中行逐渐淡出
    [self.mTableView deselectRowAtIndexPath:indexPath animated:YES];
}
//调整行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}
//调整header 高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}
//行内容进行偏移
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值