定制UITableViewCell
2013-03-18 15:30
232 查看
定制是iphone开发中常用的方法之一,这里用定制UITableViewCell来介绍一下这种解决问题的思路。
下面是GRE作业中tableCell的效果图
可以看到,cell中用到的分割线和折叠指示图标,如果用SDK提供的标准UITableViewCell实现不了,采用定制cell的思路可以简单完美地解决这个问题。
下面是代码实现:
WordCell类
@interface WordCell : UITableViewCell {
UIImageView *wrapImgSquare; //折叠指示图标
UIImageView *separImgSquare; //分隔线
}
@property(nonatomic, retain)UIImageView *wrapImgSquare;
@property(nonatomic, retain)UIImageView *sepImgSquare;
WordList.m中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @”Cell”;
WordCell *cell = (WordCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[WordCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
NSUInteger row = indexPath.row;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
GREWord *cWord = [sWordList objectAtIndex:row];
cell.textLabel.text = cWord.sName;
cell.textLabel.textColor = HEXCOLOR(WORD_COLOR);
cell.detailTextLabel.textColor = HEXCOLOR(WORD_COLOR);
cell.detailTextLabel.numberOfLines = 3;
if (cWord.bExpanded)
{
cell.detailTextLabel.text = cWord.sDetail;
cell.wrapImgSquare.image = [UIImage imageNamed:@"table_cell_unwrapped.png"];
}
else
{
cell.detailTextLabel.text = nil;
cell.wrapImgSquare.image = [UIImage imageNamed:@"table_cell_wrapped.png"];
}
[cell setBackgroundColor:[UIColor clearColor]];
return cell;
}
WordCell继承了UITableViewCell,UITableViewCell是core,WordCell附加属性是shell。代码中用自定义的WordCell替换了SDK提供的
UITableViewCell *cell,很简单的就实现了我们的需求。这个例子虽然比较简单,但是很好的展现了定制这种解决问题思路。
下面是GRE作业中tableCell的效果图
可以看到,cell中用到的分割线和折叠指示图标,如果用SDK提供的标准UITableViewCell实现不了,采用定制cell的思路可以简单完美地解决这个问题。
下面是代码实现:
WordCell类
@interface WordCell : UITableViewCell {
UIImageView *wrapImgSquare; //折叠指示图标
UIImageView *separImgSquare; //分隔线
}
@property(nonatomic, retain)UIImageView *wrapImgSquare;
@property(nonatomic, retain)UIImageView *sepImgSquare;
WordList.m中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @”Cell”;
WordCell *cell = (WordCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[WordCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
NSUInteger row = indexPath.row;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
GREWord *cWord = [sWordList objectAtIndex:row];
cell.textLabel.text = cWord.sName;
cell.textLabel.textColor = HEXCOLOR(WORD_COLOR);
cell.detailTextLabel.textColor = HEXCOLOR(WORD_COLOR);
cell.detailTextLabel.numberOfLines = 3;
if (cWord.bExpanded)
{
cell.detailTextLabel.text = cWord.sDetail;
cell.wrapImgSquare.image = [UIImage imageNamed:@"table_cell_unwrapped.png"];
}
else
{
cell.detailTextLabel.text = nil;
cell.wrapImgSquare.image = [UIImage imageNamed:@"table_cell_wrapped.png"];
}
[cell setBackgroundColor:[UIColor clearColor]];
return cell;
}
WordCell继承了UITableViewCell,UITableViewCell是core,WordCell附加属性是shell。代码中用自定义的WordCell替换了SDK提供的
UITableViewCell *cell,很简单的就实现了我们的需求。这个例子虽然比较简单,但是很好的展现了定制这种解决问题思路。
相关文章推荐
- UITableViewCell定制
- [iOS开发必备技巧之]使用IB定制UITableViewCell
- 使用XIB文件来定制你的UITableViewCell
- storyboard中用xib文件创建定制的UITableViewCell对象 .
- 定制UITableviewCell实现类似微博的分组效果
- 定制UITableViewCell
- 给定制的UITableViewCell里的控件点击设置代理
- 使用工厂模式定制UITableViewCell
- iOS 在自定制UITableViewCell 在cell的中实现点击跳页面
- 定制可隐藏seperator的UITableViewCell
- 定制UITableviewCell实现类似微博的分组效果
- xcode4.3.1定制UITableviewCell实现类似微博的分组效果
- storyboard中用xib文件创建定制的UITableViewCell对象
- UITableViewCell定制
- UITableViewCell定制总结
- xcode4.3.1定制UITableviewCell实现类似微博的分组效果
- 定制 UITableViewCell 表视图单元格
- [翻译]jQuery Mobile入门教程——主题的使用和定制
- 0005 手动定制原版 Win7 操作系统(四)
- PB5.0定制中文模拟器