我正在製作一個應用程序,使用iOS MapKit在地圖上顯示註釋。當用戶點擊註釋時,會彈出調出窗口並顯示「Tile」,「Subtitle」和「Detail Disclosure」按鈕。當用戶點擊Detail Disclosure按鈕時,我需要彈出額外的信息。當用戶點擊地圖上的詳細信息披露按鈕時,如何加載新視圖?
此附加信息可能是一個彈出窗口或其他一些被加載的視圖。我想弄清楚如何最好地做到這一點。
現在我通過在我的annotationView實現文件中使用以下代碼添加了詳細信息披露按鈕。注意行self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]
...還要注意,它被三個annotationTypes完成:
這裏是它被添加:
- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{
iCodeBlogAnnotation *myAnnotation = (iCodeBlogAnnotation*)annotation;
// setup the if/else statements
if ([myAnnotation annotationType] == iCodeBlogAnnotationTypeHotels)
{
self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
self.frame = CGRectMake(0, 0, kWidth, kHeight);
self.backgroundColor = [UIColor clearColor];
self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Hotel.png"]];
imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
[self addSubview:imageView];
}
else if([myAnnotation annotationType] == iCodeBlogAnnotationTypeAerialShots)
{
self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
self.frame = CGRectMake(0, 0, kWidth, kHeight);
self.backgroundColor = [UIColor clearColor];
self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"StreetView.jpg"]];
imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
[self addSubview:imageView];
}
else if ([myAnnotation annotationType] == iCodeBlogAnnotationTypeStreets)
{
self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
self.frame = CGRectMake(0, 0, kWidth, kHeight);
self.backgroundColor = [UIColor clearColor];
self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Street.png"]];
imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
[self addSubview:imageView];
}
然後,在我的viewController實現文件我有以下方法當用戶已經敲擊所述細節公開鍵檢測:
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
// add code here for what you want to do
}
我要補充上述方法,以加載將舉行的詳細信息的一些新的彈出式窗口或新的視圖什麼碼?
我試圖創建一個新的detailedViewController類,並在上面controllTapped法「在此處添加代碼」加入以下代碼到:
iCodeBlogMapDetailViewController *dvc = [[iCodeBlogMapDetailViewController alloc] init];
[self.navigationController pushViewController:dvc animated:YES];
但沒有任何反應。
我的下一步會是什麼?
謝謝
你的意思是在此設置IB?因爲我很確定所有的連接都已經完成 – Cybernetic 2013-04-09 21:23:41
是的。如果你的類實現了MKMapViewDelegate並且你已經設置了你的mapview的代理,那麼你上面的代碼應該可以工作。你有沒有在方法中設置斷點,NSLog等,看看控制是否到達那裏? – Kal 2013-04-09 21:27:52
我的mapView在委託和文件的所有者之間有連接。 – Cybernetic 2013-04-09 21:38:23