TableView静态单元格实现
2015-07-16 10:42
344 查看
整理TableView静态单元格的使用方法
需要实现的页面:
基本框架就是四个静态单元格,在此整理一下TableView的使用细节。
1.首先创建一个group,此内有两个类,一个是AccountBoundingViewController,继承自UIViewController;一个是AccountBoundingViewCell,继承自UITableViewCell。
2.先在xib中构造cell,内容如下:
由一个ImageView,一个Label,一个Button组成(在此并没有设定constraints),由于我的ImageView和Label内容是要变化的,而Button的状态也要有变化,所以与实现文件进行了连接。
3.在ViewController里拖进一个TableView,切记设置TableView的delegate和datasource。
4.剩下的就是在ViewController的实现文件里实现delegate和datasource的方法:
需要实现的页面:
基本框架就是四个静态单元格,在此整理一下TableView的使用细节。
1.首先创建一个group,此内有两个类,一个是AccountBoundingViewController,继承自UIViewController;一个是AccountBoundingViewCell,继承自UITableViewCell。
2.先在xib中构造cell,内容如下:
由一个ImageView,一个Label,一个Button组成(在此并没有设定constraints),由于我的ImageView和Label内容是要变化的,而Button的状态也要有变化,所以与实现文件进行了连接。
3.在ViewController里拖进一个TableView,切记设置TableView的delegate和datasource。
4.剩下的就是在ViewController的实现文件里实现delegate和datasource的方法:
@implementation AccountBoundingViewController static NSString * cellIdentify = @"AccountboundingViewCell"; - (void)viewDidLoad { [super viewDidLoad]; [self initView]; //去除表格多余行的分割线 self.tableView.tableFooterView=[[UIView alloc]init]; // detailsArray = [NSMutableArray new]; detailsArray = [NSArray arrayWithObjects:@{@"icon":@"icon_name",@"name":@"微信"},@{@"icon":@"icon_name",@"name":@"微博"},@{@"icon":@"icon_name",@"name":@"QQ"}, @{@"icon":@"icon_name",@"name":@"人人"},nil]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)initView{ self.title = @"绑定"; [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; } -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return detailsArray.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ AccountBoundingViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"AccountBoundingViewCell" owner:self options:nil] lastObject]; cell.selectionStyle = UITableViewCellSeparatorStyleNone; } NSUInteger row = [indexPath row]; cell.myLabel.text=[[self->detailsArray objectAtIndex:row] objectForKey:@"name"]; cell.icon.image = [UIImage imageNamed:@"icon_name"]; return cell; }
相关文章推荐
- unity3d 4.X音频格式
- NTFS For Mac完全读写小能手
- 字符串重组
- oracle 使表主键失效,外键失效
- ASI框架的使用
- Libgdx之封装简单的脚本机制
- linux批量重命名之xargs
- Linux文件vi操作
- Daikon Forge GUI Library(dfgui)之OnDragStart、OnDragEnd、OnDragDrop
- 获取时间并补0
- Oracle通过时间点快照来恢复数据
- 一个简单的自定义web框架
- JDK,JRE,JVM区别与联系(ZZ)
- new 对象加括号和不加括号的区别
- 打开和保存文件的对话框
- 使用连接池---jndi
- 深度学习模型之各种caffe版本(Linux和windows)的网址和配置
- Spring mvc+Easyui遇到的几个问题
- Codeforces Round #312 (Div. 2) A. Lala Land and Apple Trees 暴力
- 50个必备的实用jQuery代码段