Featured post
iphone - change view's property from method of other class -
i'm trying remotely adjust object myimageview
's alpha
to 0
of myviewcontroller
class class assistant
(it's nsobject subclass).
in assistant.h
#import <foundation/foundation.h> @class myviewcontroller; @interface assistant : nsobject { myviewcontroller *myviewcontroller; uiimageview *button; } - (void)adjustalpha:(id)sender; @property (nonatomic, retain) uiimageview *button;
in assistant.m
#import "myviewcontroller.h" @implementation assistant @synthesize button; - (id)init { self = [super init]; if (self) { myviewcontroller = [[myviewcontroller alloc] init]; nslog(@"alloced?: %@", myviewcontroller ? @"yes" : @"no"); } return self; } - (void)adjustalpha:(id)sender { nslog(@"method called"); myviewcontroller.myimageview.alpha = 0; }
the method did called, myviewcontroller.myimageview.alpha
didn't change, why? need fix? thank reading ^_^
edit
this myviewcontroller class:
myviewcontroller.h
@class assistant; @class myappappdelegate; @interface myviewcontroller : uiviewcontroller <uitextviewdelegate, uiscrollviewdelegate> { uiimageview *myimageview; assistant *assistant; } @property (nonatomic, retain) uiimageview *myimageview;
myviewcontroller.m
#import "myviewcontroller.h" #import "assistant.h" @implementation myviewcontroller @synthesize myimageview; - (void)viewdidload { [super viewdidload]; assistant = [[assistant alloc] init]; myscrollview = [[uiscrollview alloc] initwithframe:cgrectmake(0,0,320,460); [self.view addsubview: myscrollview]; myimageview = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"weather.png"]]; myimageview.frame = cgrectmake(19, 54, 48, 48); myimageview.userinteractionenabled = yes; [myscrollview addsubview:myimageview]; //this button uses call adjustalpha assistant.button = [[uiimageview alloc] initwithimage:[uiimage imagenamed:@"button.png"]]; assistant.button.frame = cgrectmake(19, 126, 48, 48); assistant.button.userinteractionenabled = yes; [myscrollview addsubview:assistant.button]; //here how call adjustalpha: assistant.adjustalphatap = [[uitapgesturerecognizer alloc] initwithtarget:assistant action:@selector(adjustalpha:)]; [assistant.button addgesturerecognizer:assistant.adjustalphatap]; }
this question got complex , need experiments, hanging there, make clear when have time. developer met same problems: declare object need access in singleton class, can accessed other classes, , merry christmas!
this work if myimageview
declared global scope variable (also called ivar) in .h file of myviewcontroller
class , has property of (nonatomic, retain)
matching @synthesize
in .m.
if sounds you're doing can please post contents of myviewcontroller
h , m files.
- Get link
- X
- Other Apps
Comments
Post a Comment