Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class method calling issue for UIImage

I have to call a Class method from a class to another class and Actually into the class method I have to pass the UIImage. so I have Created a NSObject and calling it in the Viewcontroller buttons

how to call the UIImageView and where ..please check the code where I am getting wrong..

what changes do i require in method to call 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];
}
like image 211
Christien Avatar asked Jun 10 '26 01:06

Christien


1 Answers

Your code has some serious issues:

  • Your UIImageView image1 is initialized with a CGRectZero frame - maybe it's not displayed because the frame is (0,0,0,0)? Tr giving it a real size, e.g. the image's size.

  • Next to that your ZAction objects sec and destroy will be gone at the end of the test4Action method, as they are autoreleased and not retained anywhere.

  • You also have some unnecessary semi-colons in your code - especially the one behind the method implementation of actionWithTitle I would get rid of, you can get some nasty errors with misplaced semicolons (like after an if() statement ...).

  • Please also work on your coding style (naming of variables in particular - c language keywords make no good attribute names ('object' in your action class), Aimage should be aImageView)

like image 138
TheEye Avatar answered Jun 11 '26 21:06

TheEye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!