导航控制器
//创建导航控制器
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;
}