IOS--自定义UITableViewCell
2015-10-26 13:51
369 查看
在用到UITableVIew的时候,经常会自定义每行的Cell
在IOS控件UITableView详解中的下面代码修改部分代码就可以实现自定义的Cell了
[cpp] view
plaincopy
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
自定义代码:
[cpp] view
plaincopy
static NSString *CellWithIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier];
}
NSUInteger row = [indexPath row];
// 自定义Cell中Image
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 24, 24, 24)];
imageView.image = [UIImage imageNamed:@"green.png"];
[cell.contentView addSubview:imageView];
[imageView release];
// 自定义文本信息
UILabel *city = [[UILabel alloc] initWithFrame:CGRectMake(50, 25, 100, 20)];
NSString *cityString = [[NSString alloc] initWithFormat:@"城市:%@",[self.dataList objectAtIndex:row]];
city.text = cityString;
[cell.contentView addSubview:city];
[cityString release];
// cell.textLabel.text = [self.dataList objectAtIndex:row];
// cell.imageView.image = [UIImage imageNamed:@"green.png"];
// cell.detailTextLabel.text = @"详细信息";
// cell.accessoryType = UITableViewCellSelectionStyleGray;
(转自:http://blog.csdn.net/qq5306546/article/details/8078797)
在IOS控件UITableView详解中的下面代码修改部分代码就可以实现自定义的Cell了
[cpp] view
plaincopy
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
自定义代码:
[cpp] view
plaincopy
static NSString *CellWithIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier];
}
NSUInteger row = [indexPath row];
// 自定义Cell中Image
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20, 24, 24, 24)];
imageView.image = [UIImage imageNamed:@"green.png"];
[cell.contentView addSubview:imageView];
[imageView release];
// 自定义文本信息
UILabel *city = [[UILabel alloc] initWithFrame:CGRectMake(50, 25, 100, 20)];
NSString *cityString = [[NSString alloc] initWithFormat:@"城市:%@",[self.dataList objectAtIndex:row]];
city.text = cityString;
[cell.contentView addSubview:city];
[cityString release];
// cell.textLabel.text = [self.dataList objectAtIndex:row];
// cell.imageView.image = [UIImage imageNamed:@"green.png"];
// cell.detailTextLabel.text = @"详细信息";
// cell.accessoryType = UITableViewCellSelectionStyleGray;
(转自:http://blog.csdn.net/qq5306546/article/details/8078797)
相关文章推荐
- EasyUI - 一般处理程序 返回 Json值
- MUI-图片轮播控件
- IOS--控件UITableView详解
- Set Programming Guide
- MUI-CheckBox的基本介绍
- UIImagePickerController从本地相册加载图片
- UIPageControl
- UIControlEvents
- MUI-按钮的基本使用
- request.getParameter() 和request.getAttribute() 区别
- C# WPF 模拟键盘输入与UI控件进行交互
- Virtualbox WDDM之DxgkDdiQueryDeviceDescriptor
- Mysql数据库运行过程中突然崩溃:The server quit without updating PID file
- akka quertz expressions
- 更改IOS于UISearchBar撤消button底、搜索输入文本框背景中的内容和UISearchBar底
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 反思
- UITextField学习技巧
- codeforces 591 D. Chip 'n Dale Rescue Rangers
- UIAlertController
- UIBlurEffect系统自带毛玻璃效果