我是目标 c 的新手,我正在尝试设置图像,UIImageview
同时推动viewcontroller
我检查了其他答案,我按照他们所说的方式做了同样的事情,但它对我不起作用下面是我的代码,我将在其中解释其他内容
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailViewController *svController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
UIImage *image = [UIImage imageNamed:@"default.png"];
UIImageView* imageview = [[UIImageView alloc] initWithImage:image];
id obj = [[mainArray valueForKey:@"image"] objectAtIndex:[indexPath row]];
if ([obj isKindOfClass:[NSString class]])
{
NSLog(@" image%@",image); //print this image<UIImage: 0xaa70700>
NSLog(@" image%@",svController.image); //print this image(null)
[[svController image] setImage: image];
NSLog(@" image%@",svController.image); //print this image(null)
}
else {
NSLog(@" image%@",svController.image);
[[svController image] setImage: [[mainArray valueForKey:@"image"] objectAtIndex:[indexPath row]]];
NSLog(@" image%@",svController.image);
}
[self.navigationController pushViewController:svController animated:YES];
[svController release];
svController = nil;
}
下面是我的detailviewcontroller
@interface DetailViewController : UIViewController{
UIImageView *image;
}
@property (retain, nonatomic) IBOutlet UIImageView *image;
它连接到 Xib,我已经合成了它
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
name.text = nameString;
email.text = emailString;
NSLog(@"%@",image); // print this <UIImageView: 0x9d73950; frame = (27 35; 204 181); autoresize = W+H; userInteractionEnabled = NO; layer = <CALayer: 0x9db4050>>
}
当我将它们发送NSString
并设置在我的标签上但不适用于图像时,它工作得很好,它是如此之小,但现在我不知道该怎么做,请帮忙