2

这是我的代码,我使用了谷歌地图和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"]];
}

我有一个UIPickerViewin viewDidLoad,我试过把它戴上,viewWillDisappearviewWillApear它不起作用:

- (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{
}

但是滚动不起作用。我的代码有什么问题?

4

2 回答 2

1

尝试视图上的其他位置...
我还有一个选择器,它也没有滚动,然后我移动了选择器的位置(在故事板中)并且它起作用了...
关闭自动布局也有帮助!
不满意,但解决方案...

于 2013-08-12T14:52:43.780 回答
0

请查看此工作示例以获取更多详细信息

工作教程

于 2013-07-12T04:30:28.643 回答