所以我知道这个错误的原因,但我并不确定如何解决它.
我有一个TextField,我想不可编辑,但在视图中启用滚动.
这是我如何设置该视图:
- (void)tableView:(UITableView *) tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSDictionary *component = self.resultsTuples[indexPath.row]; NSString* serverUrl = @"http://staging.toovia.com"; NSString* pageLink = component[@"$element"][@"ContactCard"][@"PageLink"]; NSString* recUrl =[NSString stringWithFormat:@"%@%@&format=json&fields=summary&fields=session_info",serverUrl,pageLink]; [AJAXUtils getAsyncJsonWithUrl:(NSURL *)[NSURL URLWithString:recUrl] callback:^(NSDictionary *returnjson){ if (returnjson != nil){ NSLog(@"RETURN JSON : %@",returnjson); NSString *userPageLink = returnjson[@"Node"][@"SessionInfo"][@"PostingAs"][@"Key"]; self.detailController.userPageLink = userPageLink; self.detailController.nodePage = returnjson[@"Node"][@"Key"]; NSString *selectedCard = component[@"$element"][@"Title"]; // [self.detailController setDescription:component[@"element"][@"ContactCard"][@"Description"]]; [self.detailController setPageTitle:selectedCard]; NSString* photoUrl = component[@"$element"][@"ContactCard"][@"Cover"][@"Medium"][@"Link"]; [self.detailController setRestaurantImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoUrl]]]]; self.detailController.title = selectedCard; NSString* rating = component[@"$element"][@"Summary"][@"AverageRating"]; self.detailController.rating =(NSInteger)rating; [self.navigationController pushViewController:self.detailController animated:YES]; } }];
这是viewWillAppear代码的视图:
-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear: animated]; self.rateView.notSelectedStar =[UIImage imageNamed:@"star-off.png"]; self.rateView.fullSelectedStar = [UIImage imageNamed:@"star-on.png"]; self.rateView.rating = self.rating; self.rateView.editable = YES; self.rateView.maxRating = 5; self.rateView.delegate = self; _pageTitleLabel.text = _pageTitle; _pageScoreLabel.text = _pageScore; _trendingImageView.image = [UIImage imageNamed:@"trending.png"]; _restaurantImageView.image = _restaurantImage; }
完整的错误是 –
2013-12-16 01:22:50.362 ReviewApp[7332:441f] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *,UIView<NSTextContainerView> *,NSTextContainer *,NSUInteger)(),/SourceCache/UIFoundation_Sim/UIFoundation-258.1/UIFoundation/TextSystem/NSLayoutManager_Private.m:1510 2013-12-16 01:22:50.365 ReviewApp[7332:441f] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: 'Only run on the main thread!'
所以我猜这是因为调整大小的文本字段(内容设置)必须发生在主线程上.如何强制此事发生/抑制此错误?我没有控制文本字段调整大小吗?
谢谢
解决方法
我猜测AJAXUtils的回调发生在后台线程上.我不知道这是否是你的代码,但是你应该在主线程上执行所有的UI操作(例如在标签中设置文本,在图像视图中设置图像,推视图控制器).
dispatch_sync(dispatch_get_main_queue(),^{ /* Do UI work here */ });
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。