我的DetailView无法加载图片

时间:2014-01-15 19:52:41

标签: ios objective-c

·H

@interface DetailViewController : UIViewController
{
      IBOutlet UILabel *sname; 
      IBOutlet UIImageView *sImage;
}

@property (strong, nonatomic)id titletwo;
@property (strong, nonatomic)id Viewimage;

的.m

@interface DetailViewController ()

@end

@implementation DetailViewController

{
    [super viewDidLoad];

    UIImage* theImage = [UIImage imageNamed:[self.Viewimage description]];
    sImage.image = theImage;

    sname.text = [self.titletwo description];

}

Viewcontroller.m

- (void)tableViewUITableView *)tableView didDeselectRowAtIndexPathNSIndexPath *)indexPath
{

    NSDictionary *tmpDict = [myObject objectAtIndex:indexPath.row];

    DetailViewController *view2 = [[[DetailViewController alloc] initWithNibName:nil bundle:nil] autorelease];

    view2.Viewimage = [tmpDict objectForKey:thumbnail];
    view2.titletwo = [tmpDict objectForKey:name];

    [self.navigationController pushViewController:view2 animated:YES];
}

我的标题可以获取数据并显示出来!但是图像不能用我做什么?

2 个答案:

答案 0 :(得分:0)

问题在于以下代码行

   DetailViewController *view2 = [[[DetailViewController alloc] initWithNibName:nil bundle:nil] autorelease];

当您使用指向nil的nib初始化DetailViewController时。

此处指定的笔尖名称

DetailViewController *view2 = [[[DetailViewController alloc] initWithNibName:@"SPECIFIED NIB NAME HERE" bundle:nil] autorelease];

答案 1 :(得分:0)

首先,您应该考虑在程序中使用仅ARC 。在.h中,您将属性定义为:

@property (strong, nonatomic)id titletwo;

使用 stong 但是在ViewController中你正在使用autorelease

DetailViewController *view2 = [[[DetailViewController alloc] initWithNibName:nil bundle:nil] autorelease];

第二次:要检查的事项:在view2.Viewimage = [tmpDict objectForKey:thumbnail];放置一个断点并在lldb窗口中打印[tmpDict objectForKey:thumbnail]的内容:

po [tmpDict objectForKey:thumbnail]

这将打印返回的值。如果它为零,则该对象中没有关键缩略图。也许你拼错thumbnail常数。

第三次:self.ViewImage看起来像是UIImage,但是你在这里使用了描述。你确定你知道哪种类型是什么?你正在使用ID ......