gpt4 book ai didi

iphone - UIImage 的类方法调用问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:22:47 25 4
gpt4 key购买 nike

我必须从一个类调用一个类方法 到另一个类,实际上我必须将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];
}

最佳答案

您的代码有一些严重的问题:

  • 您的 UIImageView image1 是使用 CGRectZero 框架初始化的 - 也许它没有显示是因为框架是 (0,0,0,0)? Tr 给它一个真实的大小,例如图片的大小。

  • 接下来,您的 ZAction 对象 sec 和 destroy 将在 test4Action 方法结束时消失,因为它们是自动释放的,不会保留在任何地方。

  • 您的代码中还有一些不必要的分号 - 尤其是我要去掉的 actionWithTitle 方法实现后面的分号,分号放错位置可能会导致一些令人讨厌的错误(例如在 if() 语句之后...)。

  • 还请改进您的编码风格(特别是变量的命名 - C 语言关键字没有好的属性名称(您的操作类中的“对象”),Aimage 应该是一个 ImageView)

关于iphone - UIImage 的类方法调用问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14960361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com