2012-04-26 31 views
10

Tôi có chế độ xem bản đồ mà tôi đang thêm và xóa annotations từ dựa trên công tắc trong số popovercontroller. Khi tôi chạm vào bên ngoài popover, nó loại bỏ chính xác và gọi phương thức delegatepopoverControllerDidDismissPopover: Vấn đề mà tôi đang gặp phải là khi tôi bật công tắc trong popover (chạm vào trong chế độ xem cửa sổ bật lên), nếu tôi xóa annotations khỏi bản đồ hoạt động chính xác và cửa sổ bật lên vẫn hiển thị nhưng nếu tôi thêm annotations vào chế độ xem bản đồ, thì popover biến mất và phương thức delegate không được gọi. Có ai đi qua hành vi này trước đây không?UIPopoverController loại bỏ mà không có đại biểu gọi

Sự khác biệt duy nhất giữa mã bật và tắt của công tắc là loại bỏ annotations khỏi một mảng, còn giá trị khác sẽ thêm annotations. Đây chỉ là vấn đề khi thêm annotations vào chế độ xem bản đồ. Bất kỳ trợ giúp hoặc đề xuất sẽ được đánh giá cao.

Đây là cách popover được hiển thị:

-(IBAction)toggleMapFiltersView:(id)sender 
{ 
    LayerPopoverViewController *popOverViewController = [[LayerPopoverViewController alloc] init]; 
    [popOverViewController setDelegate:self]; 
    [popOverViewController setBranchesShowing:branchesShowing]; 
    [popOverViewController setSchoolsShowing:schoolsShowing]; 

    [layersButton setSelected:YES]; 

    popoverController = [[UIPopoverController alloc] initWithContentViewController:popOverViewController]; 


    [popoverController setDelegate:self]; 
    [popOverViewController release]; 
    [popoverController presentPopoverFromRect:layersButton.frame 
             inView:[self view] 
        permittedArrowDirections:UIPopoverArrowDirectionAny 
            animated:YES]; 
} 

Đây là phương pháp đang được gọi là từ quan điểm popover:

-(IBAction)toggleSchools:(id)sender 
{ 
    if ([self.delegate respondsToSelector:@selector(didChangeSchoolsDisplaySettingWithVisible:)]) 
    { 
     if ([schoolsSwitch isOn]) 
     { 
     [self.delegate didChangeSchoolsDisplaySettingWithVisible:YES]; 
      self.schoolsShowing = YES; 
     } 
     else 
     { 
      [self.delegate didChangeSchoolsDisplaySettingWithVisible:NO]; 
      self.schoolsShowing = NO; 
     } 
    } 
} 

và đây là phương pháp đó là đề cập đến:

-(void)didChangeSchoolsDisplaySettingWithVisible:(BOOL)visible 
{ 
    if (visible == YES) 
    { 
     schoolsShowing = YES; 
     if (self.schoolArray != nil && [self.schoolArray count] > 0) 
     { 
      for (MySchool *school in self.schoolArray) 
      { 
       [mapView addAnnotation:school]; 
      } 
     } 
    } 
    else 
    { 
     schoolsShowing = NO; 
     for (id<MKAnnotation> annotation in mapView.annotations) 
     { 
      if ([annotation isKindOfClass:[MySchool class]]) 
      { 
       [mapView removeAnnotation:annotation]; 
      } 
     } 
    } 
} 
+0

bạn có thể đăng một số mã, do đó chúng ta có thể nhìn vào những gì đang xảy ra? – xCoder

+0

đã thêm hai phương thức có liên quan – user1359733

+0

Vui lòng cho chúng tôi biết cách bật và hiển thị cửa sổ bật lên. –

Trả lời

0

Tại sao sử dụng cửa sổ bật lên ở vị trí đầu tiên? nó sẽ dễ dàng hơn cho bạn để kiểm soát một customView.

Bạn có thể tạo popupView tùy chỉnh và đặt nó ngay phía trên tọa độ bạn muốn. cửa sổ bật lên có nút gạt và ủy quyền cuộc gọi cho tác vụ này.

Dưới đây là một số mã (trong ví dụ này, tọa độ là từ điểm đánh dấu và mapView là của google). Bạn cũng sẽ phải chuyển đổi các tọa độ thành một CGPoint.

UIAnnotationView *annotation = [[UIAnnotationView alloc] initWithFrame:CGRectMake(0,0,100,100)]; 
        annotation.delegate = self; 
        annotation.tag = 101; 

CGPoint point = [mapView.projection pointForCoordinate:marker.position]; 
     annotation.origin = CGPointMake(point.x - annotation.width/2, point.y - annotation.height - MARKER_DEFAULT_SIZE); 
     [mapView addSubview:annotation]; 

UIAnnotaionView closeButtonClicked đại biểu:

- (void)annotationViewCloseButtonClicked:(UIAnnotationView *)annotationView 
{ 
    [[_mapView viewWithTag:101] removeFromSuperview]; 
} 

Để bỏ qua popupView khi chạm vào điểm khác trong bản đồ ghi đè delegate này:

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate 
{ 
    [[_mapView viewWithTag:101] removeFromSuperview]; 
} 
+0

Popovers * do * có một loại cảm giác hệ thống cho chúng. – Undo

+0

Đúng, nhưng thay thế hợp lệ của nó. cộng với, việc tìm kiếm một thiết kế giống như cửa sổ pop dễ dàng tôi đoán .. – Lirik

0

Các bạn đã thử thêm một phương pháp đại biểu

- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController { 
    // do some stuff here and decide whether to dismiss or not 
    return YES; //or No depending on your condition 
} 

Nó sẽ hỏi bạn có muốn loại bỏ Trình điều khiển popOver hay không. Nó được gọi mỗi lần trình điều khiển popoverview sắp loại bỏ

Nếu không, bạn có thể gọi phương thức khi thêm chú thích vào chế độ xem bản đồ. Dù sao bạn biết rằng pop trên là loại bỏ. Làm công việc tương tự khi trình điều khiển bật lên bị loại bỏ. Như bạn đang làm với

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController 

Tôi hy vọng điều này có thể giúp bạn

Các vấn đề liên quan