2013-02-19 56 views
3

我必须调用Class method从一个类到另一个类,实际上进入类方法我必须通过UIImage。 所以我创建了一个NSObject,把它在Viewcontroller按钮UIImage类方法调用问题

如何调用UIImageView并在..please检查那里我得到的错误代码..

什么改变我需要在方法来电图像

Zaction.h

@interface ZAction : NSObject 

@property (retain) NSString *title; 
@property (assign) id <NSObject> target; 
@property (assign) SEL action; 
@property (retain) id <NSObject> object; 
@property(retain) UIImageView *image; 

+ (ZAction *)actionWithTitle:(NSString *)aTitle target:(id)aTarget action:(SEL)aAction object:(id)aObject image:(UIImageView *)Aimage;; 

ZAction.m

@implementation ZAction 

@synthesize title; 
@synthesize target; 
@synthesize action; 
@synthesize object,image; 

+ (ZAction *)actionWithTitle:(NSString *)aTitle target:(id)aTarget action:(SEL)aAction object:(id)aObject image:(UIImageView *)Aimage; 
{ 
    ZAction *actionObject = [[[ZAction alloc] init] autorelease]; 
    actionObject.title = aTitle; 
    actionObject.target = aTarget; 
    actionObject.action = aAction; 
    actionObject.object = aObject; 
    actionObject.image=Aimage; 
    return actionObject; 
} 

ViewController.m

#import "Zaction.h" 
- (IBAction)test4Action:(id)sender 
{ 
    UIImageView *image1=[[UIImageView alloc]initWithFrame:CGRectZero]; 
    ZAction *destroy = [ZAction actionWithTitle:@"Clear" target:self action:@selector(colorAction:) object:[UIColor clearColor] image:image1]; 
    ZAction *sec = [ZAction actionWithTitle:@"Unclear" target:self action:@selector(colorAction:) object:[UIColor clearColor] image:image1]; 
    image1.image=[UIImage imageNamed:@"icon2.png"]; 
    [self.view addSubview:image1]; 


    ZActionSheet *sheet = [[[ZActionSheet alloc] initWithTitle:@"Title" cancelAction:nil destructiveAction:destroy 
       otherActions:[NSArray arrayWithObjects:option1, nil]] autorelease]; 
    sheet.identifier = @"test4"; 
    [sheet showFromBarButtonItem:sender animated:YES]; 
} 
+1

怎么办你的意思是“如何调用UIImageView”? – trojanfoe 2013-02-19 14:55:30

+1

意味着我需要为'ZAction * destroy'和'ZAction * sec'获取图像。一些更改是获取图像的方法 – Christien 2013-02-19 14:57:19

+1

UIImage * yourImage = destroy.image.image; – Rajneesh071 2013-02-19 15:01:56

回答

1

你的代码中有一些严重的问题:

  • 你的UIImageView图像1初始化为CGRectZero框架 - 也许这不是因为显示的帧是(0,0,0,0)? Tr给它一个真实的大小,例如图像的大小。

  • 接下来,您的ZAction对象sec和destroy将在test4Action方法结束时消失,因为它们是自动释放的,不会保留在任何地方。你可能会在代码中有一些不必要的分号 - 特别是actionWithTitle的方法实现背后的一个,我会摆脱掉,你可以用错位分号(就像在if()语句之后得到一些讨厌的错误。 ..)。

  • 也请你的编码风格的工作(在特定变量的命名 - c语言的关键字,让没有好属性名称(“对象”在动作类),Aimage应aImageView)

+0

好的谢谢..但我正在'CGRectZero'框架因为这个图像将在UIActionSheet按钮..我不能定义框架的大小,..它使用'CGRectZero' ...,如果我给框架大小..将不会使用'图像的类方法':(UIImageView *)Aimage (IBAction)test4Action:(id)发送者需要的图像,像..(下) – Christien 2013-02-20 07:32:05

+0

'UIImageView * image1 = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,200,200) ]。 image1.image = [UIImage imageNamed:@“icon2.png”]; [self.view addSubview:image1]' – Christien 2013-02-20 07:32:45