IOS自定义UITableViewCell
2015-05-21 00:01
337 查看
在用到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;
在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;
相关文章推荐
- iOS开发:自定义UITableViewCell
- iOS个人整理20-UITableViewCell自定义,cell高度的自适应(纯代码)
- 根据点击头像的手势获取自定义Cell 的属性, UITableViewCell, 头像, iOS
- iOS开发15:自定义UITableViewCell
- iOS开发15:自定义UITableViewCell
- iOS-UITableViewCell自定义分割线
- IOS 自定义 tableView cell(UITableViewCell height) 高度
- [IOS]用自定义的cell来创建UITableView
- [IOS]用自定义的cell来创建UITableView
- IOS自定义表格UITableViewCell
- IOS uitableviewcell 左滑 自定义
- iOS-OC-UITableViewCell分割线自定义
- IOS UITableViewCell 自定义的label 设值重叠
- iOS UITableViewCell重用以及自定义Cell
- iOS开发15:自定义UITableViewCell
- IOS 通过 代码 自定义cell(Cell的高度不一致)(优化性能)
- 自定义UITableViewCell中获取按钮所在Cell的indexPath
- ios tableView那些事 (十五)用故事模式自定义cell
- IOS中xib+代码实现自定义cell中嵌套