iphone - how to Disable a uibutton in another class without navigating to that -
my problem different here have big view(classa) , small view on it(classb), beside small view there 4 buttons belongs class ,i want disable buttons. here code.
in classb.m
-(void)hidebuttons{ mainview = [[mainviewcontroller alloc]initwithnibname:@"mainviewcontroller" bundle:null]; [mainview hidesidebarbuttons]; }
in class b
-(void)hidesidebarbuttons{ self.pebtn.enabled = no; byviewbtn.enabled = no; favouritebtn.enabled = no; settingbtn.enabled = no; itembutton.enabled = no; addvehbtn.enabled = no; uploadallbtn.enabled = no; deletevideosbtn.enabled = no; }
these buttons not getting disabled.i'm not navigating view(cassa) i'm staying in same class;
if right understand problem, need use delegate.
in classb.h
@protocol classbdelegate <nsobject> -(void) hidesidebarbuttons; @interface classb: uiviewcontroller { __unsafe_unretained id<classbdelegate> delegate_; } @property (nonatomic, assign) id delegate; -(void)hidebuttons; @end ---------- in classb.m ---------- @implementation classb @synthesyze delegate = delegate_; -(void)hidebuttons { [self.delegate hidesidebarbuttons]; } ---------- in class mainviewcontroller need sign classbdelegate event. use code in mainviewcontroller.h ---------- @interface mainviewcontroller : uiviewcontroller <classbdelegate> in classb.h @protocol classbdelegate -(void) hidesidebarbuttons; @interface classb: uiviewcontroller { __unsafe_unretained id delegate_; } @property (nonatomic, assign) id delegate; -(void)hidebuttons; @end in classb.m @implementation classb @synthesyze delegate = delegate_; -(void)hidebuttons { [self.delegate hidesidebarbuttons]; }
in class mainviewcontroller need sign classbdelegate event. use code in mainviewcontroller.h
@interface mainviewcontroller : uiviewcontroller
when init classb
in mainviewcontroller.m
need write:
[classb setdelegate:self];
than need write classbdelegate method -(void) hidesidebarbuttons
in mainviewcontroller.m
file , disable buttons in method. example ( in mainviewcontroller.m
)
-(void) hidesidebarbuttons { self.pebtn.enabled = no; }
hope helps))
Comments
Post a Comment