将数据从表视图控制器传递到详细信息视图控制器

时间:2014-03-08 18:12:12

标签: ios objective-c

我正在尝试将我的TableViewController中的图像传递给DetailViewController。我的问题是一个逻辑问题,因为Xcode在我的代码中没有显示任何错误。当我点击任何一行并带我到DetailView时,DetailView什么也没显示,我希望DetailView向我显示我正在传递的图像。

我的TableViewController.h

#import <UIKit/UIKit.h>
#import "CustomCellControllerCell.h"
#import "DetailViewController.h"

@interface ListViewController : UITableViewController

@property (nonatomic) NSArray *foodImgArray;
@property (nonatomic) NSArray *foodTitleArray;

@end

我的TableViewController.m

- (void)viewDidLoad
{
   [super viewDidLoad];

   self.foodTitleArray = @[@"manito",
                           @"jatito",
                           @"dolorsito",
                           @"pajarito",
                           @"calalito",
                           @"chinguito"];

   self.foodImgArray = @[@"ajigallina.jpg",
                         @"anticucho.jpg",
                         @"causaRellena.jpg",
                         @"anticucho.jpg",
                         @"anticucho.jpg",
                         @"anticucho.jpg"];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

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

       DetailViewController *dvc = [segue destinationViewController];

       NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

       dvc.passedImage.image = [UIImage imageNamed:[self.foodImgArray objectAtIndex:indexPath.row]];
   }    
}

我的DetailViewController.h

#import <UIKit/UIKit.h>

@interface DetailViewController : UIViewController

@property (weak, nonatomic) IBOutlet UIImageView *detailImage;
@property (nonatomic) UIImageView *passedImage;

@end

我的DetailViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.detailImage.image = self.passedImage.image;
}

1 个答案:

答案 0 :(得分:0)

为什么不传递图像 喜欢 -

dvc.image=[UIImage imageNamed:[self.foodImgArray objectAtIndex:indexPath.row]];

并将该图像设置为DetailViewController中的detailImage,如 -

self.detailImage.image = self.image

尝试在DetailViewController中设置一些断点来检查图像是否为nil。