我想制作自定义 uitableviewcellstyle 以在我的应用程序中发表评论。我想要带有评论文本、点赞数、作者姓名、日期等的 uitableviewcell... 你有什么想法吗? 我已经创建了方法,但我不知道如何实现它。 我的代码:
- (UITableViewCell *)getCommentTableCellWithTableView:(UITableView *)tableView commentText:(NSString *)commentText numberOfRows:(NSInteger)numberOfRows numberOfLikes:(NSString *)numberOfLikes date:(NSString *)date writer:(NSString *) writerName {
static NSString *CellIdentifier = @"TitleCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return cell;
}
最佳答案
很抱歉,我找不到步骤清晰的教程,但您可以在本站搜索一些相关帖子或问题。
希望下面的简单代码可以帮助到你。
这里有个文档可能也有帮助,你花点时间看看 ;)
http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html
新类继承自UITableViewCell, CustomCell.h:
(提示:文件
->新建文件
->Objective-C类
->设置类名&选择子类UITableViewCell
)
@interface MapsListViewCell : UITableViewCell
{
// Add iVars that you want.
}
// Some custom methods
自定义单元格.m:
// ...
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
}
return self;
}
// ...
// Some custom methods
- (void)setAuthorName:(NSString *)name
{
// ...
}
TableViewController.m:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[CategoriesListViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
CategoriesListViewCell * customCell = (CategoriesListViewCell *)cell;
// Set your data:
[customCell setAuthorName:@"God"];
// ...etc.
return cell;
}
关于ios - 自定义 UITableViewCell 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8194442/