这是我的代码,我使用了Google地图和UIPickerView
:
-(void)loadView
{
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:-33.86 longitude:151.20 zoom:14];
mapViewCustomer = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapViewCustomer.myLocationEnabled = YES;
// mapView_ = [[GMSMapView alloc]initWithFrame:CGRectMake(0, 45, self.view.frame.size.width, self.view.frame.size.height)];
// [self.view addSubview:mapView_];
self.view = mapViewCustomer;
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.title = @"My location";
;
marker.map = mapViewCustomer;
[marker setIcon:[UIImage imageNamed:@"location1.png"]];
}
我在UIPickerView
中有一个viewDidLoad
,我尝试将其放在viewWillDisappear
或viewWillApear
上,但它不起作用:
- (void)viewDidLoad
{
pickerViewCustomer = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 162.0, 320.0, 120.0)];
//[pickerViewCustomer setFrame:CGRectMake(0.0, 162.0, 320.0, 120.0)];
pickerViewCustomer.hidden = YES;
pickerViewCustomer.delegate = self;
pickerViewCustomer.dataSource = self;
pickerViewCustomer.userInteractionEnabled = NO;
arrayDistanceFilters = [[NSArray alloc] initWithObjects:@"5km",@"10km",@"50km",@"100km",@"100km",@"100km",@"100km",@"100km",@"100km",@"100km", nil];
arrayDistanceValues = [[NSArray alloc] initWithObjects:[NSNumber numberWithFloat:5], [NSNumber numberWithFloat:10],[NSNumber numberWithFloat:50], [NSNumber numberWithFloat:100], nil];
[pickerViewCustomer selectRow:1 inComponent:0 animated:NO];
[pickerViewCustomer reloadAllComponents];
[self.view addSubview:pickerViewCustomer];
}
委托和数据源
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
return [arrayDistanceFilters count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [arrayDistanceFilters objectAtIndex:row];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
return 40;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
}
但滚动不起作用。我的代码出了什么问题?
答案 0 :(得分:0)
请查看此工作示例以获取更多详细信息
答案 1 :(得分:0)
在视图上尝试其他位置...
我也有一个选择器,它也没有滚动,然后我移动了选择器的位置(在故事板中)并且它工作了...
关闭autolayout也有帮助!
不满意,但解决方案......