2015-01-03 127 views
0

单击tableView单元格后显示黑屏。我能够检索该单元格上的文本,但黑屏。请帮忙。UINavigationController在单击自定义TableView单元格后显示黑屏

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    //Get cell text 
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; 
    UITableViewCell *myCell; 
    myCell = [tableView dequeueReusableCellWithIdentifier:@"BasicCell"]; 
    myCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"BasicCell"]; 
    NSString *val = selectedCell.textLabel.text; 
    [tableView deselectRowAtIndexPath:indexPath animated:NO]; 


    //Load Image view 
    UINavigationController *NavViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ImageView"]; 
    [self presentViewController:NavViewController animated:YES completion:nil]; 


} 
+0

你想要做什么?你得到一个选定的单元格,然后创建一个新的单元格,然后呈现一个导航控制器?你想从中获得什么? –

+0

您正试图在点击单元格时加载图像? –

+0

我想加载导航控制器后,选择一个单元格,并基于该选定的单元格我想在该导航控制器中加载一个URL图像。 – user3259655

回答

0

,只要你有时间,就看看这个:

didSelectRowAtIndexPath

strUrl=[self.arrImages objectAtIndex:indexPath.row]; 
[self performSegueWithIdentifier:@"ImageView" sender:nil]; 

我传递的图片网址到下一个视图控制器如上。

,然后通过strUrl下一viewController这样的:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Get the new view controller using [segue destinationViewController]. 
    // Pass the selected object to the new view controller. 

    if([[segue identifier] isEqualToString:@"ImageView"]){ 

     LoadedImageViewController *vc = [segue destinationViewController]; 
     vc.strSelectedImageUrl=strUrl; 
    } 
} 

最后,在LoadedImageViewController:在- (void)viewDidLoad添加以下代码:

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [SVProgressHUD showSuccessWithStatus:@"Loading Image..."]; 

    dispatch_async(dispatch_get_global_queue(0,0), ^{ 

     NSURL *url = [NSURL URLWithString:@"http://fpjuris.com.br/fotos/apple-iphone-3gs-01.jpg"]; 
     NSData *data = [NSData dataWithContentsOfURL:url]; 
     UIImage *img = [UIImage imageWithData:data]; 

     if (img == nil) 
      return; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      self.imgLoadedImage.image = img; 
      [SVProgressHUD dismiss]; 
     }); 
    }); 

    // Do any additional setup after loading the view, typically from a nib. 
} 

,就大功告成了! ! 所有最好的....

+0

此代码按预期工作。非常感谢卡南! – user3259655

+0

这很好...对你最好...... –

相关问题