이 내 cellForRowAtIndexPath jQuery과 위임 방법에 대한 요약 된 코드이다 :jQuery과 indexPath 부 논리
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"blahblahblah"];
if (cell == nil) {
// No cell to reuse => create a new one
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"blahblahblah"] autorelease];
}
cell.textLabel.text = @"";
cell.detailTextLabel.text = @"";
cell.backgroundView = NULL; //problem here
// Initialize cell
//blah blah blah
//now to the good part...
if(indexPath.section == 1) {
cell.backgroundView = deleteButton;
cell.userInteractionEnabled = YES;
cell.textLabel.text = nil;
cell.detailTextLabel.text = nil;
}
else if(indexPath.section == 0) {
NSLog(@"section: %i row: %i", indexPath.section, indexPath.row);
switch (indexPath.row) {
case 0:
cell.textLabel.text = @"foobar";
//more stuff
break;
//lots more cases
default:
break;
}
}
return cell;
}
내 문제 부 (1) (제 0의 첫번째 셀 10 셀 부 (1)를 갖는다는 것이다 단 1 셀만 있음)에는 첫 번째 섹션의 셀 0에 할당되는 것으로 가정되는 정보가 할당됩니다. 따라서, deleteButton background와 etc를 얻지 않고, 레이블 제목 "foobar"를 얻습니다. 내 if 문이 매우 명확하기 때문에 왜 이런 일이 발생하는지 잘 모르겠습니다. 어떤 아이디어?
편집 : backgroundView를 NULL로 설정하면 텍스트가있는 셀이보기를 벗어날 때 배경없이 되돌아옵니다. 따라서 이것이 가능한 솔루션이 아닙니다. 또한 detailTextLabel의 텍스트는 텍스트가 없어야하는 셀에 설정됩니다.
이가 전무로 설정 셀 backgroundViews 및 삭제 셀을 보여주는 텍스트로 모양을 어디는 안 :
솔루션, 알렉스 간주 할 (권장)이 코드와 함께 오래 디큐 코드를 교체 :
NSString* identifier;
if(indexPath.section == 0)
identifier = @"0";
else
identifier = @"1";
UISwitch *switchView;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
// No cell to reuse => create a new one
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier] autorelease];
아, 그래, 그랬어. 해결책으로 질문을 업데이트했습니다. –