안녕하세요 그룹 테이블에 uilabel 추가하려고합니다. 내가 사용한 모든 접근 방식은 셀 생성에 대한 내 모든 논리가 uitableviewcellforrowatindexpath에 있습니다. 즉; 나는 별도의 클래스 (예 : customcell.h 또는 이와 비슷한 것을 사용하지 않는다.)를 사용한다. 레이블을 추가하는 데는 성공했지만 사용자 정의 변경 사항은 제로 0 행에만 반영됩니다. 다음 if (indexpath.section == 0) 및 if (indexpath.section == 1) 여전히 변경 사항은 섹션 0 행에만 반영됩니다. 또한 모든 셀의 모양과 느낌이 필요하기 때문에 if 절의 필요가 없습니다. 같은. ? 여기 내 코드입니다 : 당신 때문에 스크롤 할 때uitableview 셀 및 그룹화 된 테이블에 uilabel 추가하려고 : 0 구역 행에 반영하는 변경
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
//code STATS here : initializing here for cells background view & selection back ground view
cell.backgroundView =
[[[UIImageView alloc] init] autorelease];
cell.selectedBackgroundView =
[[[UIImageView alloc] init] autorelease];
//code ENDS HERE of initializing
//custom label
UIImage *indicatorImage = [UIImage imageNamed:@"indicator.png"];
cell.accessoryView =
[[[UIImageView alloc]
initWithImage:indicatorImage]
autorelease];
const CGFloat LABEL_HEIGHT = 20;
UIImage *image = [UIImage imageNamed:@"filter.png"];//this image is on top //left of section zero rows
//
// Create the label for the top row
//
topLabel =
[[[UILabel alloc]
initWithFrame:
CGRectMake(
image.size.width + 2.0 * cell.indentationWidth,
0.5 * (aTableView.rowHeight - 2 * LABEL_HEIGHT),
aTableView.bounds.size.width -
image.size.width - 4.0 * cell.indentationWidth
- indicatorImage.size.width,
LABEL_HEIGHT)]
autorelease];
[cell.contentView addSubview:topLabel];
//
// Configure the properties for the text that are the **SAME** on every row
//
topLabel.tag = TOP_LABEL_TAG;
topLabel.backgroundColor = [UIColor clearColor];
topLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
topLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
topLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
//testing:
[email protected]"test1";
//
// Create the label for the top row of text
//
bottomLabel =
[[[UILabel alloc]
initWithFrame:
CGRectMake(
image.size.width + 2.0 * cell.indentationWidth,
0.5 * (aTableView.rowHeight - 2 * LABEL_HEIGHT) + LABEL_HEIGHT,
aTableView.bounds.size.width -
image.size.width - 4.0 * cell.indentationWidth
- indicatorImage.size.width,
LABEL_HEIGHT)]
autorelease];
[cell.contentView addSubview:bottomLabel];
//
// Configure the properties for the text that are the same on every row
//
bottomLabel.tag = BOTTOM_LABEL_TAG;
bottomLabel.backgroundColor = [UIColor clearColor];
bottomLabel.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
bottomLabel.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
bottomLabel.font = [UIFont systemFontOfSize:[UIFont labelFontSize] - 2];
[email protected]"test2";
}
//testing for section 2
//this image is on top left of section one rows
UIImage *image1 = [UIImage imageNamed:@"akshardham.jpg"];
topLabel1 =
[[[UILabel alloc]
initWithFrame:
CGRectMake(
image1.size.width + 2.0 * cell.indentationWidth,
0.5 * (aTableView.rowHeight - 2 * LABEL_HEIGHT),
aTableView.bounds.size.width -
image1.size.width - 4.0 * cell.indentationWidth
- indicatorImage.size.width,
LABEL_HEIGHT)]
autorelease];
[cell.contentView addSubview:topLabel1];
topLabel1.tag = TOP_LABEL_TAG1;
topLabel1.backgroundColor = [UIColor clearColor];
topLabel1.textColor = [UIColor colorWithRed:0.25 green:0.0 blue:0.0 alpha:1.0];
topLabel1.highlightedTextColor = [UIColor colorWithRed:1.0 green:1.0 blue:0.9 alpha:1.0];
topLabel1.font = [UIFont systemFontOfSize:[UIFont labelFontSize]];
//testing:
[email protected]"test2section";
}
}
else
{
topLabel = (UILabel *)[cell viewWithTag:TOP_LABEL_TAG];
bottomLabel = (UILabel *)[cell viewWithTag:BOTTOM_LABEL_TAG];
topLabel1 = (UILabel *)[cell viewWithTag:TOP_LABEL_TAG1];
}
어떤 제안 덕분에 ..
헤이 감사 지적에 대한 난 그냥 경우 주석 (셀 == 전무) {} 사물이 잘 가고있다 ...하지만 그것은 좋은 방법입니다 경우 ... 나는 그냥 이걸보고 .. 어떤 r & D 및 인터넷 검색을 – Alok
항상 코드에서 동일한 패턴을 사용하십시오 : * 나는 코멘트가 형식화 된 코드에 좋지 않기 때문에 내 대답에 넣어 * – Zoleas