1

我有一个带有注释的 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;
}
}

}
4

1 回答 1

0

activityI您使用的不一定threadInfo是附加到正在使用的 annotationView 的那个(info变量)。它只是通过调用创建的最后一个,viewForAnnotation可以随时为任何注释调用。您需要获取打开的活动指示器info。这里有一些伪代码让你开始。获取附件视图,然后获取您添加的活动指示器的子视图viewForAnnotation

popButton = (UIButton*) info.rightCalloutAccessoryView;
UIActivityIndicator *currentActivityIndicator = (UIActivityIndicator *)[popButton **Get the right subview here**];

另一种选择是直接将附件视图设置为信息按钮

info.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoLight];

您将 popButton 指向 rightCalloutAccessoryView,然后将其指向一个新按钮,但这不会改变 rightCalloutAccessoryView

于 2013-02-26T20:52:53.577 回答