0
기본보기에는 3 개의 버튼이 있고 2 개의 버튼에는 이벤트 선택을위한 UIPickerView
이 있어야합니다)와 시간의 선택 (두 번째).UIpickerView에서 요소를 변경하는 방법 버튼을 누르거나 다른 버튼을 누르는 방법
UIPickerViewDelegate
오직 한 번 방법을 구현하도록하겠습니다. 따라서 UIPickerView
의 내용을 변경하려면 어떻게해야합니까?
#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 FROM 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];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be 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 FROM rutas WHERE 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 FROM config_ruta WHERE 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 {
}
일부 도움을주세요 ... 당신이 눌러 진 버튼을 나타내는 플래그를 설정해야
작동하는지, 감사합니다,하지만 난 첫 번째 버튼을 누르시면 지금은 또 다른 문제가있을 때 하나의 행을 선택하고 다른 버튼을 누르면, pickerView는 첫 번째 버튼의 데이터를 보여줍니다. 그리고 두 번째 버튼을 먼저 누르면 데이터 양식의 두 번째 버튼이 표시되고 한 행을 선택하고 다른 버튼을 누르면 pickerView는 내가 처음 누른 버튼의 데이터를 표시합니다. 행을 선택하고 pickerView를 숨길 때 모든 데이터를 제거하는 방법은 무엇입니까? – leirbaggmj
두 단추 방법 ('buttonType' 속성 설정 후)에서 선택보기를 다시로드해야합니다. – rmaddy
고마워요 !! 그것은 작동합니다! – leirbaggmj