为什么UITextView会阻碍iOS中的主线程?

时间:2016-11-23 08:54:20

标签: ios objective-c user-interface

每当应用程序按下包含文本视图的控制器时,屏幕将停止一秒。就像您在主线程中放入互联网请求的效果一样。我试图在全局队列中初始化文本视图,但它没有工作。

文本视图属于名为" FNMFeedbackTitleView"的自定义视图。 文本视图的代码初始化如下:

@implementation FNMFeedbackTitleView
NSInteger currentWords = 0;

NSString *_currentText = nil;
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = FNWhiteColor;
        currentWords = 0;
        _currentText = nil;
        [self initializedSubviews];//containing the initializing of text view    }
    return self;
}

初始化如下:

//text view initialize
UITextView *textView = [[UITextView alloc]initWithFrame:CGRectZero];
textView.frame= CGRectMake(horizonalMargin, CGRectGetMaxY(adviceLabel.frame)+verticalMargin, FNDeviceWidth-2*horizonalMargin, 100);
textView.delegate = self;
textView.backgroundColor = FNWhiteColor;
[self addSubview:textView];
_textView = textView;

自定义视图(FNMFeedbackTitleView)初始化FNMFeedbackViewController,如下所示:

 //titleView
    _titleView = [[FNMFeedbackTitleView alloc]initWithFrame:CGRectMake(0, 0, FNDeviceWidth, 100)];

自定义视图将是collectionview

中的标题视图
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableView = nil;
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"headerview" forIndexPath:indexPath];
        if (reusableView.subviews.count ==  0) {
            [reusableView addSubview:_titleView];
        }
    }else {
        reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"footerview" forIndexPath:indexPath];
        if (reusableView.subviews.count ==  0) {
            [reusableView addSubview:_footerView];
        }
    }
    return reusableView;
}

推动动作:

FNMFeedbackViewController *feedbackController = [FNMFeedbackViewController new];
[self.navigationController pushViewController:feedbackController animated:YES];

0 个答案:

没有答案