我必须从类中调用Class method
到另一个类,实际上我必须传递UIImage
类方法。
所以我创建了NSObject
并在Viewcontroller
按钮
如何调用UIImageView
并在哪里..请查看我出错的代码..
我在调用图像的方法中需要进行哪些更改
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];
}
答案 0 :(得分:1)
您的代码存在一些严重问题:
你的UIImageView image1是用CGRectZero框架初始化的 - 也许它没有显示,因为框架是(0,0,0,0)? Tr给它一个真实的大小,例如图像的大小。
接下来你的ZAction对象sec和destroy将在test4Action方法结束时消失,因为它们是自动释放的,不会保留在任何地方。
你的代码中也有一些不必要的分号 - 特别是actionWithTitle的方法实现背后的一个我会摆脱,你可以用错误的分号得到一些讨厌的错误(比如在if()之后的语句...)。
请同时处理您的编码风格(特别是变量的命名--c语言关键字没有好的属性名称(动作类中的'对象'),Aimage应该是aImageView)