0

我想在按下 rightcalloutaccessoryview 按钮时添加一个新视图。我目前具有在地图上放置图钉的功能。当我点击图钉时,会加载带有标题、副标题和 V 形的标注 (MKAnnotation)。当我点击 V 形 (rightcalloutaccessoryview) 时,我希望弹出另一个视图,此时显示更多信息。现在,人字形水龙头什么也没做。这就是我所拥有的:

-(IBAction)showInfo:(id)sender 
{     
     int calloutButtonPressed = ((UIButton *)sender).tag;
     if(calloutButtonPressed < 99999)
     {
          if(self.DetailView == nil)
          {
               DetailViewController *tmpViewController = [[UIViewController alloc] initWithNibName:@"DetailView" bundle:nil];
               self.DetailView = tmpViewController;
               [tmpViewController release];
          }

          if (calloutButtonPressed == 1) 
          {
                         // Using the debugger, I found that calloutButtonPressed is equal to 0 when the button is pressed.
                         // So I'm not sure what the point of this method is...
                }
          self.DetailView.title = @"Title";
     }
 }

我已经验证了这个动作方法确实会在按下 V 形时被调用。不幸的是,我无法让它拉出一个新的视图。如果有人知道我做错了什么,请告诉我。我有点紧张...

谢谢!

托马斯

4

1 回答 1

0
    -(IBAction)showInfo:(id)sender 
{   
     int calloutButtonPressed = ((UIButton *)sender).tag;
     if(calloutButtonPressed < 99999)
     {
          if(self.detailView == nil)
          {
               DetailViewController *tmpViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
               self.detailView = tmpViewController;
               [tmpViewController release];
          }

          [self.navigationController pushViewController:self.detailView animated:YES];

          if (calloutButtonPressed == 0) 
          {
               // TRP - I inserted my view atIndex:99999 to ensure that it gets placed in front of all windows
               // TODO: figure a better way to do this
               [self.view insertSubview:detailView.view atIndex:99999];
          }
          self.detailView.title = @"Title";
     }

}

它缺少这一声明:

[self.view insertSubview:detailView.view atIndex:99999];

我想找到另一种方法,这样我就不必在那里有那个神奇的数字(99999)(另外,它似乎有点不成熟......)。我不太担心它,因为它虽然有效。

我从 Apple 开发者论坛获得了帮助,请点击此处

于 2010-02-19T22:24:28.393 回答