在重用单元格时,将标签添加到第一个UITableViewCell行
是否可以在重用单元格时向UITableViewCell添加标签?这是我一直在尝试的代码,但当我向下滚动并重新使用单元格时,我的标签会四处移动。我只想把标签一直放在第一行,但我一辈子也弄不明白这一点。我知道我不能重复使用细胞,它将工作,但我想重复使用细胞。请帮我弄清楚。非常感谢你在重用单元格时,将标签添加到第一个UITableViewCell行,uitableview,uilabel,Uitableview,Uilabel,是否可以在重用单元格时向UITableViewCell添加标签?这是我一直在尝试的代码,但当我向下滚动并重新使用单元格时,我的标签会四处移动。我只想把标签一直放在第一行,但我一辈子也弄不明白这一点。我知道我不能重复使用细胞,它将工作,但我想重复使用细胞。请帮我弄清楚。非常感谢你 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
if ([indexPath row] == 0) {
UILabel* Label = [[UILabel alloc] initWithFrame:CGRectMake(2,2, 62, 23)];
[Label setText:@"Text"];
[cell addSubview:Label];
[Label release];
}
return cell;
}
我想我明白了。我让第一排不能重复使用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellsToBeReused = @"CellsToBeReused";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellsToBeReused];
if (cell == nil){
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellsToBeReused] autorelease];
}
if ([indexPath row] == 0) {
UITableViewCell *first_Cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
UILabel* Label = [[UILabel alloc] initWithFrame:CGRectMake(2,2, 62, 23)];
[Label setText:@"Text"];
Label.backgroundColor = [UIColor whiteColor];
[first_Cell.contentView addSubview:Label];
[Label release];
return first_Cell;
} else {
return cell;
}
}