我有一个带有注释的 mapView,它们有一个按钮作为右附件视图。如果您在注释详细信息出现时立即按下按钮,则详细信息显示为空,因为没有足够的时间下载所需的信息。我正在寻求的是显示一个活动指示器,只要该信息正在下载。这是我到目前为止所拥有的:
-(MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation{
popButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 31, 31)];
[popButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];
activityI = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 31, 31)];
[activityI startAnimating];
[popButton addSubview:activityI];
[NSThread detachNewThreadSelector:@selector(threadInfo:) toTarget:self withObject:annotation];
.
.
.
annView.rightCalloutAccessoryView = popButton;
}
-(void) threadInfo: (MKAnnotationView*) info{
while ([activityI isAnimating]) {
if (ok ==0) {
}
else{
NSLog(@"ok = %i",ok);
popButton = (UIButton*) info.rightCalloutAccessoryView; <--error*
popButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[activityI removeFromSuperview];
[activityI stopAnimating];
ok=0;
}
}
}
其中 "ok" = 整数 其中 1 = 下载过程成功完成时
其中错误 = 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[“注释类名称”rightCalloutAccessoryView]:无法识别的选择器发送到实例 0x17e7fc60'
即使我注释掉按钮,我仍然会在没有崩溃的情况下进行动画处理..
更新:(所有注释掉的东西都已经过测试并且不能正常工作 - 不一定同时。任何没有注释的东西都是我最后一次尝试)......
-(void) threadInfo: (MKAnnotationView*) annView{
UIButton* popButtons = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 31, 31)];
act = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 31, 31)];
[act setColor:[UIColor greenColor]];
[act startAnimating];
[popButtons addSubview:act];
while ([act isAnimating]) {
if (ok ==0) {
NSLog(@"ok = %i",ok);
}
else{
NSLog(@"ok = %i",ok);
// popButton = (UIButton*) annView.rightCalloutAccessoryView;
//UIButton* popButtons = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 31, 31)];
popButtons = [UIButton buttonWithType:UIButtonTypeInfoLight];
// UIActivityIndicatorView *currentActivityIndicator = (UIActivityIndicatorView *)[popButton viewWithTag:15];
//currentActivityIndicator.hidden = YES;
//[popButtons addSubview:[(UIActivityIndicatorView*) [popButton viewWithTag:15]]];
// [(UIActivityIndicatorView *) [popButton viewWithTag:15] stopAnimating];
// [(UIActivityIndicatorView *) [popButton viewWithTag:15] removeFromSuperview];
annView.rightCalloutAccessoryView = popButtons;
//[popButton addSubview:popButtons];
// NSLog(@"view = %@",[popButton viewWithTag:15]);
//[act stopAnimating];
// [currentActivityIndicator stopAnimating];
// [currentActivityIndicator removeFromSuperview];
// popButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
//ok=0;
}
}
}