2014-07-10 5 views
1

커스텀 테이블 셀을 클릭했을 때 이미지를 표시하기 위해 다음 코드를 사용했습니다. 그러나 검은 화면을 클릭하면 테이블보기로 돌아 가지 않고 검은 색 화면도 표시됩니다. 사전ImageView가 uitable로 돌아 오지 않습니다.

+0

컨트롤러를보기 위해 subView로 imageView를 추가하지 않았습니다. – Injectios

+0

귀하의 작업은 선택기 여야하며 그렇게 사용할 수 없으며 미리보기 이미지를 표시하는 좋은 방법은 아닙니다. – BoranA

+0

imageView와 imageVC의 관계는 무엇입니까? imageVC에 imageView를 추가 하시겠습니까? – jailani

답변

1

에서

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    CustomTableViewCell *cell = tableView.visibleCells[indexPath.row]; 
    UIViewController *imageVC = [UIViewController new]; 
    CGRect screenRect = [[UIScreen mainScreen] bounds]; 
    CGFloat screenWidth = screenRect.size.width; 
    CGFloat screenHeight = screenRect.size.height; 
    imageVC.view.frame = CGRectMake(0, 0, screenWidth, screenHeight); 
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:imageVC.view.frame]; 
    cell.vendorImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:fullImg]]]; 
    // cell.imageView.image = fullImg; 
    imageView.image = cell.vendorImage.image; 
    imageView.userInteractionEnabled=YES; 
    UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:imageView.hidden=YES]; 
    [imageView addGestureRecognizer:tapGR]; 
    [self presentViewController:imageVC animated:YES completion:nil]; 

} 

덕분에 당신은 imageVC에 이미지를 추가하지 않습니다. 검정색 인 빈보기 컨트롤러를 표시하고 있습니다.

UIViewController의 하위 클래스를 만들어야합니다. 보기 컨트롤러에 NSImage 속성을 추가하십시오. 클래스에 이미지보기를 추가하고 loadView (또는 인터페이스 작성기 파일 (xib 또는 스토리 보드))에서 초기화하십시오.

- (void)loadView { 
    UIView *contentView = [[UIView alloc] initWithFrame:...]; 

    self.imageView = [[UIImageView alloc] initWithFrame:...]; 

    [contentView addSubview:self.imageView]; 

    self.view = contentView; 
} 

viewWillAppear:의 이미지보기로 설정하십시오.

- (void)viewWillAppear:(BOOL)animated { 
    [super viewWillAppear:animated]; 

    self.imageView.image = self.image; 
} 

닫기 닫기를 클릭하십시오.

- (void)dismiss { 
    [self dismissViewControllerAnimated:YES completion:nil]; 
} 

는 다음과 같이 뷰 컨트롤러를 제시 :

MyImageViewController *imageVC = [[MyImageViewController alloc] init]; 
cell.vendorImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:fullImg]]]; 
imageVC.image = cell.vendorImage.image; 
imageView.userInteractionEnabled=YES; 
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss)]; 
[imageView addGestureRecognizer:tapGR]; 
[self presentViewController:imageVC animated:YES completion:nil]; 
+0

왜 투표가 늦습니까? – dasdom

+0

내가하지 않았어 –

+0

그것은 이미지를 표시하지만 갑자기 빈 화면으로 바뀐다 –

0

당신의 UIView를 사용할 수 있으며 테이블보기 위의 현재보기에이보기를 추가 할 수 있으며, 추가하는 대신 새의 UIViewController를 만들기위한 필요 없음 그것 위로 이미지보기.

+0

어떤 샘플 코드로 도울 수있다. –

관련 문제