iOS 导航控制器、标签、表视图的创建方法
2013-12-27 11:52
411 查看
导航控制器
//创建导航控制器
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;
}
相关文章推荐
- 详解iOS开发中使用storyboard创建导航控制器的方法
- iOS开发:如何通过响应者链条获取到导航、标签等控制器呢?
- iOS开发UITabBarController的几种代理方法以及结合NSUserDefaults还原上次退出时被选中视图控制器和视图控制器的顺序
- IOS中视图控制器与标签传递nib的输出口outlet
- iOS之浅谈纯代码控制UIViewController视图控制器跳转界面的几种方法
- iOS基础之UITabBarController(标签视图控制器)
- IOS学习(六)导航视图控制器
- iOS导航控制器和标签栏控制器的结合
- iOS自定义导航控制器侧滑返回的多种实现方法
- iOS个人整理16-标签视图控制器--UITabBarController
- iOS开发导航控制器下不同视图控制器之间切换:利用CATrasition和view的layer层来实现自定义的动画效果
- IOS使用视图控制器和视图(二)通过 UISwitch 创建及使用开关
- iOS- 浅谈纯代码控制UIViewController视图控制器跳转界面的几种方法
- iOS UI-(多)视图控制器的生命周期、加载方法和模态视图方法以及屌丝方法
- iOS中的UITabBarController(标签视图控制器)
- ios学习记录 day31 UI 9 多视图切换 导航控制器
- iOS Dev 深入浅出 导航控制器(二)with表视图相关操作
- iOS多视图控制器跳转方法
- ios视图控制器与标签传递nib的输出口outlet
- iOS结合导航控制器和标签栏控制器