简体   繁体   中英

UINavigationController is showing black screen after clicking on custom TableView cell

Showing black screen after I click on a tableView cell. I am able to retrieve the text on that cell but with the black screen. Please help.

-(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];


} 

Whenever You get time, just look at this:

On didSelectRowAtIndexPath :

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

I am passing the Image url to the next view controller as above.

And then, pass the strUrl to the next viewController like this:

- (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;
    }
}

And lastly, in the LoadedImageViewController : add this code in - (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.
}

And you are done!!! All the best....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM