使用按钮触发器将didFinishLaunchingWithOptions:方法移动到viewcontroller方法 [英] move didFinishLaunchingWithOptions: method to viewcontroller method with button trigger

查看:52
本文介绍了使用按钮触发器将didFinishLaunchingWithOptions:方法移动到viewcontroller方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AppDelegate.h / .m中使用以下代码,但无法通过触发它的按钮将其更改为在ViewController中工作。

I had the following code working in AppDelegate.h/.m but cannot change it to work in ViewController with a button triggering it.

@implementation BSViewController

@synthesize imageView;
@synthesize workingImage;
- (IBAction) chooseImage:(id) sender {

    UIImage* testCard = [UIImage imageNamed:@"ipad 7D.JPG"];
    CGImageRef num = CGImageCreateWithImageInRect([testCard CGImage],CGRectMake(532, 0, 104, 104));
    UIGraphicsBeginImageContext(CGSizeMake( 250,650));
    CGContextRef con = UIGraphicsGetCurrentContext();
    UIImage* im = UIGraphicsGetImageFromCurrentImageContext();
    CGContextDrawImage(con, CGRectMake(0, 0, 13, 13) ,num);
    UIGraphicsEndImageContext();
    CGImageRelease(num);

    UIImageView* iv = [[UIImageView alloc] initWithImage:im];
    [self.imageView addSubview: iv];
    iv.center = self.imageView.center;
    [iv release];

我在模拟器中看到名为 Choose image的按钮,但在那里看不到图像。

I see the button named "Choose image" in the simulator, but I do not see the image there.

推荐答案

您尚未向任何视图添加 self.imageView
您需要

You haven't added self.imageView to any views. You need

[self.view addSubview:self.imageView];

显示您的imageView。

To show your imageView.

这篇关于使用按钮触发器将didFinishLaunchingWithOptions:方法移动到viewcontroller方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆