UINavigationController 在单击自定义 TableView 单元格后显示黑屏
UINavigationController is showing black screen after clicking on custom TableView cell
单击 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];
}
有时间就看看这个:
在 didSelectRowAtIndexPath
:
strUrl=[self.arrImages objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:@"ImageView" sender:nil];
我正在将图像 url 传递给上面的下一个视图控制器。
然后,将 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.
}
大功告成!!!
祝一切顺利....
单击 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];
}
有时间就看看这个:
在 didSelectRowAtIndexPath
:
strUrl=[self.arrImages objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:@"ImageView" sender:nil];
我正在将图像 url 传递给上面的下一个视图控制器。
然后,将 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.
}
大功告成!!! 祝一切顺利....