0
이것은 내 cellForRowAtIndexPath
함수입니다. 작동하려면 레이블에 setText
을 가져올 수 없습니다. 나 좀 도와 줄 수있어?iphone SDK : viewWithTag와 함께 셀을 다시 사용할 수 없습니다 (레이블을 다시 사용하도록 텍스트를 설정할 수 없음).
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UILabel *messageLabel = nil;
int row = [indexPath row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, ROWHEIGHT) reuseIdentifier:CellIdentifier];
messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 5, 240, 60)];
[messageLabel setFont:[UIFont fontWithName:@"ArialMT" size:12]];
[messageLabel setTextColor:[UIColor blackColor]];
[messageLabel setBackgroundColor:[UIColor clearColor]];
[messageLabel setNumberOfLines:3];
[messageLabel setLineBreakMode:UILineBreakModeWordWrap];
[messageLabel setTag: messageTag];
[cell.contentView addSubview:messageLabel];
}
else{
messageLabel = (UILabel *)[cell viewWithTag:messageTag];
}
[messageLabel setText:[[[aSingleton wallItemArray] objectAtIndex:row] message]];
NSLog(@" -- > at row %d, message: %@", row, [[[aSingleton wallItemArray] objectAtIndex:row] message]);
return cell;
}
예 나는 그것을 시도했다하지만 런타임 오류가있어 : 인해 캐치되지 않는 예외 'NSInvalidArgumentException', 이유에 종료 응용 프로그램을 '*** - [UIView의의 setText이 :] : 인식 할 수없는 선택기 인스턴스 0xf4a0c0로 전송' 오시는 길 그것은 UILabel가 아닌 UIView로 그것을 recorgnizes ...? – RoundOutTooSoon
아, 그 경우 원래의 인스턴스를 다시 얻지 못합니다. 'messageTag'값은 무엇입니까? 다른보기의 태그를 복제하면 (예를 들어, 모든보기의 태그를 변경하지 않으면 태그가 0이됩니다) 잘못된보기가 다시 나타납니다. – iKenndac
U는 Ken을 알기 때문에 messageTag를 0으로 설정하고 이것이 내 문제를 일으켰습니다. 난 임의의 숫자로 342343 그것을 변경하고 작동합니다 !! Yeehaaa !!! 이 문제는 당신이 나에게 켄에게 대답 할 때까지 많은 시간을 낭비했습니다. 정말 고마워! 음료 나 무언가를 사 줄 수 있겠습니까? "예를 들어, 모든보기의 태그는 변경하지 않으면 0입니다." 매우 유용한 정보! Ken에 감사드립니다! – RoundOutTooSoon