Uitableview 带有自定义单元格的表视图(以编程方式)
到目前为止,我曾经创建自定义笔尖来制作我想要的单元格,但这一次,单元格的高度将从一个变为另一个,因此我无法创建固定大小的单元格笔尖 所以我决定以编程方式创建它。。。下面的方法是实现它的好方法吗Uitableview 带有自定义单元格的表视图(以编程方式),uitableview,row,customization,cell,reusability,Uitableview,Row,Customization,Cell,Reusability,到目前为止,我曾经创建自定义笔尖来制作我想要的单元格,但这一次,单元格的高度将从一个变为另一个,因此我无法创建固定大小的单元格笔尖 所以我决定以编程方式创建它。。。下面的方法是实现它的好方法吗 // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILabel *pseudoAndDate = [[UILabel alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,20.0)];
[pseudoAndDate setTag:1];
[cell addSubview:pseudoAndDate];
[pseudoAndDate release];
}
CommentRecord *thisRecord = [comments objectAtIndex:[indexPath row]];
UILabel *label = (UILabel *)[cell viewWithTag:1];
[label setText:[NSString stringWithFormat:@"%@ | %@",thisRecord.author,thisRecord.date]];
return cell;
}
或者。。我是不是遗漏了什么?因为到目前为止它似乎不起作用;)
谢谢
Gotye.为什么不需要创建标签呢?使用UITableViewCell的标签
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
CommentRecord *thisRecord = [comments objectAtIndex:[indexPath row]];
cell.textLabel.text = [NSString stringWithFormat:@"%@ | %@",thisRecord.author,thisRecord.date];
return cell;
}
如果您的问题是每个单元的高度不同,您可以使用以下方法: :
从UITableViewDelagate实现它以编程方式为自定义UITableViewCell创建新链接请注意,这是不鼓励的,因此答案应该是搜索解决方案的终点(与另一个参考的中途停留相比,它往往会随着时间的推移而过时)。请考虑在这里添加一个独立的概要,将链接作为参考。