活动的指标作为标注配件 [英] Activity indicator as annotation accessory

查看:140
本文介绍了活动的指标作为标注配件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与他们有一个按钮,右附件查看注释的图形页面。如果你一旦标注细节出现那么preSS按钮的细节显示为空,因为没有足够的时间来下载所需的信息。我所寻求的是只要有这些信息被下载到显示出活动的指标。这里是我到现在为止:

   - (MKAnnotationView *)的MapView:(*的MKMapView)毫伏viewForAnnotation:(ID< MKAnnotation>){注解popButton = [[的UIButton的alloc] initWithFrame:方法CGRectMake(0,0,31,31)];
[popButton addTarget:自我行动:@选择(按钮:) forControlEvents:UIControlEventTouchUpInside];
activityI = [[UIActivityIndi​​catorView的alloc] initWithFrame:方法CGRectMake(0,0,31,31)];
[activityI startAnimating]
[popButton addSubview:activityI];
[NSThread detachNewThreadSelector:@选择(的ThreadInfo :) toTarget:自withObject:注释]。



annView.rightCalloutAccessoryView = popButton;
} - (无效)的ThreadInfo:(MKAnnotationView *){信息而([activityI isAnimating]){
    如果(OK == 0){    }
    其他{        的NSLog(@OK =%I,确定);
        popButton =(UIButton的*)info.rightCalloutAccessoryView; < - 错误*
        popButton = [UIButton的buttonWithType:UIButtonTypeInfoLight];
        [activityI removeFromSuperview]
        [activityI stopAnimating]
        确定= 0;
        }
    }}

其中,OK=整数,其中1 =当下载过程成功完成

,其中误差=终止应用程序由于未捕获的异常'NSInvalidArgumentException',原因:' - [的注释类名rightCalloutAccessoryView]:无法识别的选择发送到实例0x17e7fc60

甚至当我注释掉按钮activityI仍然没有动画..崩溃

更新时间:(。一切都注释掉已经过测试,在同一时间没有工作 - 不是一定凡是没有评论我的最后一次尝试了)...

   - (空)的ThreadInfo:(MKAnnotationView *)annView {
的UIButton * popButtons = [[的UIButton的alloc] initWithFrame:方法CGRectMake(0,0,31,31)];
行为= [[UIActivityIndi​​catorView的alloc] initWithFrame:方法CGRectMake(0,0,31,31)];
[动作的setColor:[的UIColor绿彩]];
[行事startAnimating]
[popButtons addSubview:行为];
而([法isAnimating]){
            如果(OK == 0){
        的NSLog(@OK =%I,确定);    }
    其他{        的NSLog(@OK =%I,确定);      // popButton =(UIButton的*)annView.rightCalloutAccessoryView;
//的UIButton * popButtons = [[的UIButton的alloc] initWithFrame:方法CGRectMake(0,0,31,31)];
        popButtons = [UIButton的buttonWithType:UIButtonTypeInfoLight];
       // UIActivityIndi​​catorView * currentActivityIndi​​cator =(UIActivityIndi​​catorView *)[popButton viewWithTag:15];
        //currentActivityIndi​​cator.hidden = YES;
        // [popButtons addSubview:[​​(UIActivityIndi​​catorView *)[popButton viewWithTag:15]]];
// [(UIActivityIndi​​catorView *)[popButton viewWithTag:15] stopAnimating];
// [(UIActivityIndi​​catorView *)[popButton viewWithTag:15] removeFromSuperview];
        annView.rightCalloutAccessoryView = popButtons;
        // [popButton addSubview:popButtons];
      //的NSLog(@视图=%@,[popButton viewWithTag:15]);
        // [行事stopAnimating]// [currentActivityIndi​​cator stopAnimating]
// [currentActivityIndi​​cator removeFromSuperview]      // popButton = [UIButton的buttonWithType:UIButtonTypeInfoLight];    // OK = 0;
}
}}


解决方案

在您使用的的ThreadInfo activityI 不一定是附加到正在使用的annotationView的之一(信息变量)。这只是是通过调用创建 viewForAnnotation 可在任何时间以任何注释被称为最后一个。你需要获得该活动的指标,是信息。下面是一些伪code启动你。获取accessoryView的,然后得到的子视图是您在 viewForAnnotation

添加活动的指标

  popButton =(UIButton的*)info.rightCalloutAccessoryView;
UIActivityIndi​​cator * currentActivityIndi​​cator =(UIActivityIndi​​cator *)[popButton **这里得到正确的子视图**]

另一个选择是只直出设置accessoryView的为INFO按钮

  info.rightCalloutAccessoryView = [UIButton的buttonWithType:UIButtonTypeInfoLight];

您都指向popButton到rightCalloutAccessoryView,那么你是在一个新的按钮指向它,但是这并没有改变rightCalloutAccessoryView

I have a mapView with annotations which they have a button as right accessory view. If you press the button as soon as the annotation details appear then details appear to be empty because there was not enough time to download the required information. What I am seeking is to show an activity indicator as long as there that info is downloading. Here is what I have until now:

-(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;
        }
    }

}

where "ok" = integer where 1 = when downloading process completes successfully

where error = Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-["annotation class name" rightCalloutAccessoryView]: unrecognized selector sent to instance 0x17e7fc60'

even when I comment out the button the activityI still animates without crashes..

Updated: (everything commented out has been tested and not working -not necessarily at the same time. Anything that is not commented was my last try)...

-(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;
}
}

}

解决方案

The activityI you are using in threadInfo is not necessarily the one attached to the annotationView that is being used (the info variable). It's just the last one that was created by a call to viewForAnnotation which can be called at any time for any annotation. you need to get the activity indicator that is on info. Here's some pseudo code to start you off. Get the accessoryView, then get the subview that is the activity indicator you added in viewForAnnotation

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

Another option would be to just straight out set the accessoryview to the info button

info.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeInfoLight];

You were pointing popButton to the rightCalloutAccessoryView, then you were pointing it at a new button, but that doesn't change rightCalloutAccessoryView

这篇关于活动的指标作为标注配件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆