您的位置:首页 > 其它

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的方法:

@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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: