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