그래서 기본적으로 내가 사용자 지정 UITableViewCell (이 경우 UIImageView 중간에 설정된 간단한 셀이 있습니다.) 제대로 서브 클래 싱 된 (셀 및 이미지보기 .h .m 파일이 있습니다. 제대로 "퇴장했다").사용자 정의 UITableViewCell
셀을로드 할 때 UIImageView를 원으로 변경하고 UIImageView에 제스처 인식기를 추가 할 수 있어야합니다 (사용자가 ImageView를 탭하면 UIImagePicker를로드합니다. 사용자가 이미지를 설정).
내가 직면 한 문제는 코드가 디버거에 따라 실행되지만 UI가 업데이트되지 않는다는 것입니다. (여전히 일반 사각형 UIImageView가 보이고 제스처 인식기가 작동하지 않습니다.) 여기
는 cellforrowatindexpath 위임 방법에 대한 코드이다. I도 [셀 setNeedsdisplay]와 함께합니다 (willdisplaycell 위임 방법에서 동일한 코드를 넣고 있지만, 그 중 작동하지 않는 시도-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row==0 && indexPath.section==0) {
static NSString *CellIdentifier = @"Profile Cell";
Profileviewcell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[Profileviewcell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.ProfileImage.layer.cornerRadius = cell.ProfileImage.bounds.size.width/2;
cell.ProfileImage.layer.masksToBounds = YES;
[cell.ProfileImage setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(LoadImage:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[cell.ProfileImage addGestureRecognizer:tap];
[cell setNeedsDisplay];
return cell;
} else {
//return a standard cell
}
}
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0 && indexPath.section==0) {
Profileviewcell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
cell.ProfileImage.layer.cornerRadius = cell.ProfileImage.bounds.size.width/2;
cell.ProfileImage.layer.masksToBounds = YES;
[cell.ProfileImage setUserInteractionEnabled:YES];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(LoadImage:)];
tap.cancelsTouchesInView = YES;
tap.numberOfTapsRequired = 1;
tap.delegate = self;
[cell.ProfileImage addGestureRecognizer:tap];
[cell setNeedsDisplay];
}
}
Initwithstyle 코드 :
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.ProfileImage = [[UIImageView alloc] initWithFrame:CGRectMake(110,5,100,100)];
[self.ProfileImage setImage:[UIImage imageNamed:@"General Profile"]];
self.ProfileImage.layer.cornerRadius = self.ProfileImage.bounds.size.width/2;
self.ProfileImage.layer.masksToBounds = YES;
[self.ProfileImage setUserInteractionEnabled:YES];
[self.contentView addSubview:self.ProfileImage];
}
return self;
}
셀 UI가 절대로 업데이트되지 않는 이유에 대한 아이디어가 있습니까? 유사한 문제에 대해 Stack Overflow를 확인했고 제공되는 모든 솔루션이 나에게 적합하지 않은 것 같습니다. 죄송합니다. 간단한 질문 인 경우 - 최근에야 iOS 개발을 시작했습니다.
많은 감사!
의 이름으로 스토리 보드 셀의 클래스를 설정
cellForRowAtIndexPath
nil
확인되어 제거 제스처 인식기? 그렇다면, 당신이 가지고있는 문제를 설명 할 것입니다. – bobnoble@bobnoble 답장을 보내 주셔서 대단히 감사합니다! 예, 디버거에 따라 아무 것도 아니지만 정확히 이유는 모르겠습니다! 셀은 스토리 보드의 프로토 타입 셀이며 Xcode의 UITableViewCell 하위 클래스도 만들었습니다. 내가 그것을 멈추게하면 어떻게 될까요? (그리고 왜 처음부터 무의미한가요?) –
커스텀'UITableViewCell'에 대한 코드를 보여줍니다. 특히'ProfileImage'가 선언되어있는 곳과'initWithStyle' 메소드의 일부로 어떻게 초기화되어 있는지를 보여줍니다. – bobnoble