ios - how to change elements on UIpickerView pushing a button or pushing another button -
i have application, in main view, have 3 buttons, , 2 firts buttons have show uipickerview
selection of event (one of them) , selection of time (the second).
uipickerviewdelegate
let me implement methods 1 time, so, how can change content of uipickerview
.
here mi .m code:
#import "home_viewcontroller.h" @interface home_viewcontroller () @end @implementation home_viewcontroller @synthesize index,arrayhoras,arrayrutas,pickerview, rutaid, horas, botonhoras, botonruta, hora; - (ibaction)selectruta:(id)sender { [uiview beginanimations:nil context:nil]; [uiview setanimationduration:0.3]; [self.view addsubview:pickerview]; [uiview commitanimations]; [pickerview sethidden:no]; } - (ibaction)horasboton:(id)sender { [uiview beginanimations:nil context:nil]; [uiview setanimationduration:0.3]; [self.view addsubview:pickerview]; [uiview commitanimations]; [pickerview sethidden:no]; } - (void)viewdidload { [super viewdidload]; hora = 1; arrayrutas = [[nsmutablearray alloc] init]; arrayhoras = [[nsmutablearray alloc] initwithobjects: @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11", @"12", nil]; sqlite3 *turutadb; nsarray *dirpath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *databasepath = [[dirpath objectatindex:0] stringbyappendingpathcomponent:@"turuta.db"]; nslog(@"path de la bbdd: %@", databasepath); if(sqlite3_open([databasepath utf8string], &turutadb)==sqlite_ok) { nslog(@"2 base de datos creada y abierta con exito"); } else { nslog(@"ha fallado la apertura de la bbdd"); } sqlite3_stmt *sentenciarutas; nsstring *querysqlrutas = @"select id,nombre rutas"; if(sqlite3_prepare_v2(turutadb, [querysqlrutas utf8string], -1, &sentenciarutas, null)==sqlite_ok){ nslog(@"consulta preparada ok"); } else { nslog(@"consulta ha fallado al preparar: %s", sqlite3_errmsg(turutadb)); } while (sqlite3_step(sentenciarutas) == sqlite_row) { nsstring *selectrutas = [[nsstring alloc] initwithutf8string: (const char *) sqlite3_column_text(sentenciarutas, 1)]; [arrayrutas addobject:selectrutas]; } sqlite3_finalize(sentenciarutas); // [self.tabbarcontroller.tabbar sethidden:yes]; // additional setup after loading view, typically nib. } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } - (nsinteger)numberofcomponentsinpickerview:(uipickerview *)pickerview { return 1; } - (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component { if(!botonhoras.istouchinside) { return [arrayhoras count]; } else { return [arrayrutas count]; } } - (nsstring *)pickerview:(uipickerview *)pickerview titleforrow:(nsinteger)row forcomponent:(nsinteger)component { if(!botonhoras.istouchinside) { return [arrayhoras objectatindex:row]; } else { return [arrayrutas objectatindex:row]; } } - (void)pickerview:(uipickerview *)pickerview didselectrow:(nsinteger)row incomponent:(nsinteger)component { if (!botonhoras.istouchinside) { horas= [[arrayhoras objectatindex:row] intvalue]; botonhoras.titlelabel.text = [nsstring stringwithformat:@"%d horas", horas]; [self.pickerview removefromsuperview]; } else { //gmspolylineoptions *optionsline = [gmspolylineoptions options]; gmsmutablepath *ruta = [gmsmutablepath path]; sqlite3 *turutadb; nsarray *dirpath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *databasepath = [[dirpath objectatindex:0] stringbyappendingpathcomponent:@"turuta.db"]; nslog(@"path de la bbdd: %@", databasepath); if(sqlite3_open([databasepath utf8string], &turutadb)==sqlite_ok) { nslog(@"2 base de datos creada y abierta con exito"); } else { nslog(@"ha fallado la apertura de la bbdd"); } sqlite3_stmt *sentenciaid; nsstring *querysqlid = [nsstring stringwithformat: @"select id rutas nombre = '%@'", [arrayrutas objectatindex:row]]; if(sqlite3_prepare_v2(turutadb, [querysqlid utf8string], -1, &sentenciaid, null)==sqlite_ok){ nslog(@"consulta preparada ok"); } else { nslog(@"consulta ha fallado al preparar: %s", sqlite3_errmsg(turutadb)); } while (sqlite3_step(sentenciaid) == sqlite_row) { nsstring *id = [[nsstring alloc] initwithutf8string: (const char *) sqlite3_column_text(sentenciaid, 0)]; rutaid = [id intvalue]; nslog(@"%d",rutaid); } sqlite3_finalize(sentenciaid); sqlite3_stmt *sentenciapolyline; nsstring *querysqlpoliline =[nsstring stringwithformat: @"select coordx,coordy config_ruta id_ruta = %d", rutaid]; if(sqlite3_prepare_v2(turutadb, [querysqlpoliline utf8string], -1, &sentenciapolyline, null)==sqlite_ok){ nslog(@"consulta preparada ok"); } else { nslog(@"consulta ha fallado al preparar: %s", sqlite3_errmsg(turutadb)); } while (sqlite3_step(sentenciapolyline) == sqlite_row) { nsstring *x = [[nsstring alloc] initwithutf8string: (const char *) sqlite3_column_text(sentenciapolyline, 1)]; nsstring *y = [[nsstring alloc] initwithutf8string: (const char *) sqlite3_column_text(sentenciapolyline, 0)]; double coordx = [x doublevalue]; double coordy = [y doublevalue]; nslog(@"%f | %f",coordy,coordx); [ruta addcoordinate:cllocationcoordinate2dmake(coordy, coordx)]; } sqlite3_finalize(sentenciapolyline); botonruta.titlelabel.text = [arrayrutas objectatindex:row]; [self.pickerview removefromsuperview]; [pickerview selectrow:0 incomponent:0 animated:yes]; } } - (ibaction)rutaboton:(id)sender { }
some please...
you need set flag indicating button pressed. check flag in each of picker view data source , delegate methods.
add int
property class. in selectruta:
method set property 1
. in horasboton:
method, set property 2
.
then picker view method (this assumes property named buttontype
):
- (nsinteger)pickerview:(uipickerview *)pickerview numberofrowsincomponent:(nsinteger)component { if(self.buttontype == 1) { return [arrayrutas count]; } else { return [arrayhoras count]; } }
Comments
Post a Comment