IOS TableView 用法
来源:互联网 发布:老司机求网址 知乎 编辑:程序博客网 时间:2024/05/16 16:59
1.在视图上创建TableView( 拖控件),为ViewController创建UITableView属性(链接至TableView)和NSArray属性(存储数据)
ViewController.h@property (strong, nonatomic) NSArray *list;@property (weak, nonatomic) IBOutlet UITableView *tableView;
2.为UIViewController实现UITableViewDelegate,UITableViewDataSource两个协议
ViewController.h@interface ViewController : UIViewController<UITableViewDelegate,UITableViewDataSource>@property (strong, nonatomic) NSArray *list;@property (weak, nonatomic) IBOutlet UITableView *tableView;@end
3.同步属性
ViewController.c@synthesize list = _list;
4.设置tableview数据源的数据,显示代理 以及显示区域等.
ViewController.c- (void)viewDidLoad{ [super viewDidLoad]; NSArray *array = [[NSArray alloc] initWithObjects:@"美国", @"菲律宾", @"黄岩岛", @"中国", @"泰国", @"越南", @"老挝", @"日本" ,nil]; self.list = array; [self.tableView setFrame:CGRectMake(0, 0, 320, 420)]; [self.tableView setDataSource:self]; [self.tableView setDelegate:self]; }
5.绘制表格单元
ViewController.c//Draw tableview cell-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *TableSampleIdentifier = @"TableSampleIdentifier"; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:TableSampleIdentifier]; if(cell == nil){ cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableSampleIdentifier]; } NSUInteger row = [indexPath row]; cell.textLabel.text=[self.list objectAtIndex:row]; return cell;}-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.list count];}
0 0
- IOS tableview用法备忘
- IOS TableView 用法
- ios:TableView的用法
- iOS tableView 控件用法 [转]
- iOS之tableView基本用法
- IOS开发 tableview中cell的用法
- IOS开发 tableview中cell的用法
- IOS开发 tableview中cell的用法
- IOS开发 tableview中cell的用法
- IOS开发中TableView的关键用法
- iOS tableView 控件用法 [0] UITableView的基本用法
- iOS tableView 控件用法 [1] UITableCell的基本用法
- ios tableview
- iOS tableView
- TableView iOS
- ios tableview
- iOS---tableview
- [iOS]TableView
- 1065. A+B and C (64bit) (20)
- 结构体指针内的指针变量成员的内存分配
- ARC Semantic issue:No visiable @interface for xxx declares the selector yyy编译错误
- iOS开发中编译通过Success但有红色警告
- Linux设备模型 (1)
- IOS TableView 用法
- 劝君惜取少年时
- 跟着实例学习java多线程7-对象的组合发布
- 没有重写 归档和反归档的方法 编译报错
- 线程:避免死锁
- 2.2工作日志
- LeetCode 8.String to Integer (atoi)
- USB 知识整理合辑
- sign签名参数值无效,解决办法