iphone - How to update a UIButton label from another view controller -


i have uitabbar application, has 3 tabs. first tab has uiviewcontroller uibutton displays modal uiviewcontroller allow user select date. i'm having trouble updating label of uibutton when user has selected chosen date.

my main view controller .h / .m

#import <uikit/uikit.h>  @interface searchviewcontroller : uiviewcontroller {     iboutlet uibutton *butfromdate; }  @property (nonatomic, retain) uibutton *butfromdate;  - (ibaction)pickdate:(id)sender;  @end  ////////////////////////////////////////////  #import "searchviewcontroller.h" #import "searchdatepickerviewcontroller.h"  @implementation searchviewcontroller  @synthesize butfromdate;  - (ibaction)pickdate:(id)sender{     searchdatepickerviewcontroller *sampleview = [[[searchdatepickerviewcontroller alloc] init] autorelease];      [sampleview setmodaltransitionstyle:uimodaltransitionstylepartialcurl];     [self presentmodalviewcontroller:sampleview animated:yes]; }  - (void)dealloc {     [butfromdate release];     [super dealloc]; }  @end 

then modal window (with uipicker, , couple of uibarbuttons cancel or save user's choice) .h / .m looks like:

#import <uikit/uikit.h>  @interface searchdatepickerviewcontroller : uiviewcontroller <uipickerviewdelegate, uipickerviewdatasource> {     nsmutablearray *dates;     iboutlet uipickerview *picker; }  @property (nonatomic, retain) nsmutablearray *dates; @property (nonatomic, retain) uipickerview *picker;  - (ibaction)canceldatepick:(id)sender; - (ibaction)pickdate:(id)sender;  @end  ////////////////////////////////////////////  #import "searchdatepickerviewcontroller.h" #import "searchviewcontroller.h" #import "appdelegate.h" #import "search.h"  @implementation searchdatepickerviewcontroller  @synthesize dates, picker;  - (ibaction)canceldatepick:(id)sender{     [self dismissmodalviewcontrolleranimated:yes]; }  - (ibaction)pickdate:(id)sender{     holidaycottagesappdelegate *appdelegate = (holidaycottagesappdelegate *)[[uiapplication sharedapplication] delegate];     searchviewcontroller *searchview = [searchviewcontroller alloc];     appdelegate.currentsearch.fromdate = [dates objectatindex:[picker selectedrowincomponent:0]];      [searchview.butfromdate settitle:@"hello-test" forstate:uicontrolstatenormal];     [self dismissmodalviewcontrolleranimated:yes]; }  - (void)viewdidload {     [super viewdidload];     nsdate* curdate = [nsdate date];     nscalendar* calendar = [[nscalendar alloc] initwithcalendaridentifier:nsgregoriancalendar];     nsdatecomponents* comps = [calendar components:nsyearcalendarunit|nsmonthcalendarunit|nsweekcalendarunit|nsweekdaycalendarunit fromdate:curdate];     nstimezone* gmt = [nstimezone timezonewithabbreviation:@"gmt"];     dates = [[nsmutablearray alloc] init];      [comps settimezone:gmt];     [comps setweekday:7];      int startcount = comps.week + 1;     int endcount = (((52 - startcount) + 52) + startcount);      (startcount; startcount <= endcount; startcount++){         nsdate *tdate = [calendar datefromcomponents:comps];         [dates addobject:tdate];         [comps setweek:startcount];     } }  // other shizzle here not needed display... 

so, when click save button, runs -(void)pickdate: ok , dismisses modal view, won't update searchviewcontroller's uibutton label "hello-test". i'm sure i'm missing simple here...

please me!!

thanks :)

in main view controller, need pass "self" reference search date picker view controller, , set ivar main view controller in search date picker view , use reference in pickdate method of search date picker view. please check out blog entry of mine last year on exact subject:

http://www.dosomethinghere.com/2009/10/04/passing-values-and-messages-between-views-on-iphone/


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -