#在蓝懿学习iOS的日子#Day13
2015-11-06 20:10
363 查看
一、导航控制力器NavigationControeller
在第一个 ViewController前添加一个NavigationControeller,新建第二个页面 SecondViewController
1、、在 ViewController.m导入
#import "SecondViewController.h"
@implementation ViewController
- (IBAction)leftAction:(UIBarButtonItem *)sender {
NSLog(@"左按钮");
}
- (IBAction)clicked:(id)sender {
SecondViewController *vc = [[SecondViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
//创建系统样式按钮
UIBarButtonItem *bbi1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(rightAction)];
//创建文字按钮
UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithTitle:@"右按钮" style:UIBarButtonItemStyleDone target:self action:@selector(rightAction)];
// self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:bbi1,bbi2, nil];
self.navigationItem.rightBarButtonItems = @[bbi1,bbi2];
}
-(void)rightAction{
NSLog(@"右按钮");
}
2、在 SecondViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"第二个页面";
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(backAction) userInfo:nil repeats:NO];
}
-(void)backAction{
//跳回上一个页面
[self.navigationController popViewControllerAnimated:YES];
}
二、 UITableView
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *names;
@end
@implementation ViewController
//控制tableView有几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
//控制每个区有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.names.count;
}
//控制每行显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//去内存中找 有没有离开页面的cell 有得话 拿过来直接用 没有则为nil
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//如果没有拿到离开页面的cell则需要创建一个
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSLog(@"%ld-%ld",indexPath.section,indexPath.row);
}
NSString *name = self.names[indexPath.row];
cell.textLabel.text = name;
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.names = [NSMutableArray array];
[self.names addObject:@"刘德华"];
[self.names addObject:@"张学友"];
[self.names addObject:@"郭富城"];
UIBarButtonItem *addItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAction)];
self.navigationItem.leftBarButtonItem = addItem;
}
-(void)addAction{
NSString *name = @"王";
[self.names addObject:name];
//在ViewDidLoad方法之后 修改数据源数组的话 需要让tableView重新加载
[self.tableView reloadData];
}
在第一个 ViewController前添加一个NavigationControeller,新建第二个页面 SecondViewController
1、、在 ViewController.m导入
#import "SecondViewController.h"
@implementation ViewController
- (IBAction)leftAction:(UIBarButtonItem *)sender {
NSLog(@"左按钮");
}
- (IBAction)clicked:(id)sender {
SecondViewController *vc = [[SecondViewController alloc]init];
[self.navigationController pushViewController:vc animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
//创建系统样式按钮
UIBarButtonItem *bbi1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(rightAction)];
//创建文字按钮
UIBarButtonItem *bbi2 = [[UIBarButtonItem alloc]initWithTitle:@"右按钮" style:UIBarButtonItemStyleDone target:self action:@selector(rightAction)];
// self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:bbi1,bbi2, nil];
self.navigationItem.rightBarButtonItems = @[bbi1,bbi2];
}
-(void)rightAction{
NSLog(@"右按钮");
}
2、在 SecondViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"第二个页面";
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(backAction) userInfo:nil repeats:NO];
}
-(void)backAction{
//跳回上一个页面
[self.navigationController popViewControllerAnimated:YES];
}
二、 UITableView
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong)NSMutableArray *names;
@end
@implementation ViewController
//控制tableView有几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
//控制每个区有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.names.count;
}
//控制每行显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//去内存中找 有没有离开页面的cell 有得话 拿过来直接用 没有则为nil
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
//如果没有拿到离开页面的cell则需要创建一个
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
NSLog(@"%ld-%ld",indexPath.section,indexPath.row);
}
NSString *name = self.names[indexPath.row];
cell.textLabel.text = name;
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.names = [NSMutableArray array];
[self.names addObject:@"刘德华"];
[self.names addObject:@"张学友"];
[self.names addObject:@"郭富城"];
UIBarButtonItem *addItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addAction)];
self.navigationItem.leftBarButtonItem = addItem;
}
-(void)addAction{
NSString *name = @"王";
[self.names addObject:name];
//在ViewDidLoad方法之后 修改数据源数组的话 需要让tableView重新加载
[self.tableView reloadData];
}
相关文章推荐
- iOS应用性能优化备忘录
- IOS开发—CAShapeLayer与CAGradientLayer
- iOS培训第四周第三5天(OC第5讲)
- 苹果开发 笔记(89)第三方 iOS 富文本组件
- ios打包IPA的各种问题和解决方法
- iOS开发21-OC学习- #include、#import和@class,解决#import死循环
- ios控制器modal跳转
- iOS本地通知
- iOS获取应用程序信息,版本号,程序名等
- IOS基础分享
- ios程序打包成ipa包过程
- iOS Runtime详解之SEL,Class,id,IMP,_cmd,isa,method,Ivar
- iOS登陆选择主界面
- iOS简单的登陆界面代码
- iOS image 添加图片
- iOS 自动化测试之xcpretty简介
- IOS-24-iOS动态库与静态库的区别及原理
- iOS学习之Table View的简单使用(前辈写的哦,仅是收藏一下,好仔细啊,赞!)
- 属性 iOS笔记
- 属性 iOS笔记