【问题标题】:Class method calling issue for UIImageUIImage 的类方法调用问题
【发布时间】:2013-02-04 07:17:29
【问题描述】:

我必须将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];
}

【问题讨论】:

  • “如何调用 UIImageView”是什么意思?
  • 意味着我需要为ZAction *destroyZAction *sec 获取图像。获取图像的方法有哪些变化
  • UIImage *yourImage = destroy.image.image;
  • 是的,image 属性命名错误,应该是 imageView
  • @Rajneesh071 是的,但图像不显示...类方法是否正确?并且图像会以同样的方式在test4Action 中被调用??

标签: iphone ios methods uiimage


【解决方案1】:

您的代码存在一些严重问题:

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

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

  • 1234563 ...)。
  • 还请注意您的编码风格(特别是变量的命名 - c 语言关键字不会产生好的属性名称(您的操作类中的“对象”),Aimage 应该是 aImageView)

【讨论】:

  • 好的,谢谢.. 但我正在使用CGRectZero 框架,因为此图像将在 UIActionSheet 按钮上..我无法将框架大小定义为,.. yi 使用它CGRectZero。 ..如果我给出帧大小..将不会使用image:(UIImageView *)AimageClass method ,因为我将定义到的所有东西 - (IBAction)test4Action:(id)sender 所需的图像像..(下)
  • UIImageView *image1=[[UIImageView alloc]initWithFrame:CGRectMake(10,10,200,200)]; image1.image=[UIImage imageNamed:@"icon2.png"]; [self.view addSubview:image1]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-10
  • 1970-01-01
  • 2012-09-18
  • 1970-01-01
  • 2011-07-24
相关资源
最近更新 更多