Problem with calling a class method for UIImage
I need to call Class method
from a class to another class, but in fact, I need to pass it to a class method UIImage
. so i created NSObject
and typed it in buttonsViewcontroller
how to call UIImageView
and where..please check the code where i am wrong ..
what changes do i need in the method to call the image
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];
}
source to share
There are serious problems in your code:
-
Your UIImageView image1 is initialized with a CGRectZero frame - maybe it isn't showing because the frame is (0,0,0,0)? Tr gives it the real size, for example. image size.
-
Next to that, your ZAction sec and destroy objects will disappear at the end of the test4Action method as they are auto-implemented and not persisted anywhere.
-
You also have some unnecessary semicolons in your code - especially the one behind the actionWithTitle implementation method, which I would get rid of, you might get some nasty errors with inappropriate semicolons (e.g. after an if () ...) ...
-
Please also work on your coding style (variable naming in particular - c words do not contain good attribute names ("object" in your action class), Aimage must be aImageView)
source to share