У меня есть 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;
}
}
}
где «хорошо» = целое число, где 1 не = когда процесс загрузки завершается успешно
где ошибка = Нагрузочный приложение из-за неперехваченного исключением «NSInvalidArgumentException», причина: «- [ «имя класса аннотаций» rightCalloutAccessoryView]: непризнанные селектор направил к экземпляру 0x17e7fc60'
даже когда я закомментируйте кнопку activityI еще оживляющее без сбоев ..
Обновлено: (все комм был протестирован и не работает - не обязательно в одно и то же время. Все, что не комментируется была моя последней попыткой) ...
-(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;
}
}
}
Как я знаю, вы отправляете аннотацию вместо annView в методе [NSThread detachNewThreadSelector: @ selector (threadInfo :) toTarget: self withObject: аннотация]; – user247
Как вы предлагаете мне это исправить? спасибо. – user1780591
просто измените аннотацию на annView в этом методе [NSThread detachNewThreadSelector: @selector (threadInfo :) toTarget: self withObject: аннотация]; – user247