2014-10-09 9 views
1

내 앱이 layoutSubview 메소드에서 충돌하는 경우가 있습니다. 앱이 UITableViewCell의 높이를 계산할 때 발생합니다. 때때로 앱 충돌이 발생합니다. 여기에 기능 코드 : 나는 메모리 관리 문제라고 생각iOS SIGSEGV SEGV_ACCERR 레이아웃 충돌 내비게이션

- (void)layoutSubviews { 
    [super layoutSubviews]; // Sometimes crashed here 

    CGFloat contentLeft = kTextInsets.left; 

    BOOL isReply = self.editorialCommentData.inReplyToCommentId != 0; 

    if (isReply) { 
     contentLeft += kAuthorLeftInset + self.authorImageView.frameWidth; 
    } 

    self.authorImageView.frameOrigin = CGPointMake(contentLeft, kContentInsets.top); 

    self.votesLabel.frameWidth = 200; // Sometimes crashed here 
    [self.votesLabel sizeToFit]; 

    self.votesLabel.frameTop = self.authorImageView.frameTop - 1.5f; 
    self.votesLabel.frameRight = self.contentView.bounds.size.width - kContentInsets.right; 

    <.....more code here.....> 
} 

: 여기

Thread : Crashed: com.apple.root.default-qos 
0 UIKit       0x2ff92b3a -[_UIViewAdditiveAnimationAction runActionForKey:object:arguments:] + 569 
1 UIKit       0x2ff92cf5 __67-[_UIViewAdditiveAnimationAction runActionForKey:object:arguments:]_block_invoke + 408 
2 QuartzCore      0x2f71e4c5 CA::Layer::end_change(CA::Transaction*, unsigned int, objc_object*) + 96 
3 QuartzCore      0x2f71f06b CA::Layer::set_bounds(CA::Rect const&, bool) + 530 
4 QuartzCore      0x2f71ed87 -[CALayer setBounds:] + 110 
5 UIKit       0x3017f84f -[_UILabelLayer setBounds:] + 58 
6 QuartzCore      0x2f71fe01 -[CALayer setFrame:] + 600 
7 UIKit       0x3017f7eb -[_UILabelLayer setFrame:] + 58 
8 UIKit       0x2fcfc4d7 -[UIView(Geometry) setFrame:] + 254 
9 UIKit       0x2fd09f53 -[UILabel setFrame:] + 138 
CRASH->10 MYAPP      0x000fb611 -[UIView(Frame) setFrameWidth:] (UIView+Frame.m:103) 
11 MYAPP      0x00130c75 -[EditorialCommentCell layoutSubviews] (EditorialCommentCell.m:139) 
12 MYAPP      0x001324ed +[EditorialCommentCell heightForEditorialCommentData:] (EditorialCommentCell.m:351) 
13 MYAPP      0x00115733 -[EditorialCommentsViewModel applyDataFromItem:toVMItem:] (EditorialCommentsViewModel.m:298) 
14 MYAPP      0x00114e73 -[EditorialCommentsViewModel vmDataFromItem:] (EditorialCommentsViewModel.m:222) 
15 MYAPP      0x000fac29 -[FatherViewModel insertItemsUpdatingExisting:intoVMItems:] (FatherViewModel.m:418) 
16 MYAPP      0x000f9cfd __39-[FatherViewModel updateItems:failure:]_block_invoke_3 (FatherViewModel.m:281) 
17 libdispatch.dylib    0x3a4718cb _dispatch_call_block_and_release + 10 
18 libdispatch.dylib    0x3a47ada3 _dispatch_root_queue_drain + 834 
19 libdispatch.dylib    0x3a47bcd7 _dispatch_worker_thread3 + 94 
20 libsystem_pthread.dylib  0x3a5d2e31 _pthread_wqthread + 668 

내 layoutSubview 코드 : 여기

+ (CGFloat)heightForEditorialCommentData:(EditorialCommentVMData *)editorialData 
{ 
    EditorialCommentCell * cell = [EditorialCommentCell instanceCell]; 
    [cell applyViewModelData:editorialData]; 
    [cell layoutSubviews]; 
    return cell.commentTextLabel.frameBottom + kTextInsets.bottom; 
} 

+ (EditorialCommentCell *)instanceCell { 
    static EditorialCommentCell *instance = nil; 

    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     NSArray *views = [[NSBundle mainBundle] loadNibNamed: @"EditorialCommentCell" owner:0 options:0]; 
     instance = views[0]; 
     instance.frame = CGRectMake(instance.contentView.frame.origin.x, 
             instance.contentView.frame.origin.y, 
             [[UIScreen mainScreen] bounds].size.width, 
             instance.contentView.frame.size.height); 
    }); 

    return instance; 
} 

는 스택 추적한다.

+0

귀하의 문제와 관련이 있는지 모르겠지만 layoutSubviews 메서드에 관한 Apple 설명서에 "이 메서드를 직접 호출해서는 안됩니다. 레이아웃을 강제로 업데이트하려면 setNeedsLayout 메서드를 대신 호출하십시오. 다음 드로잉 업데이트 전에 그렇게해야합니다. " –

+0

@MarcoPace 오, 고마워요, 지금 시도 할게요! – ItsTipTop

답변

0

OK! 나는 그것을 고쳤다. layoutSubviews 메서드에 대한 Marco의 의견 : "이 메서드를 직접 호출해서는 안됩니다. 레이아웃을 강제로 업데이트하려면 다음 드로잉 업데이트 전에 setNeedsLayout 메서드를 호출하십시오." layoutIfNeeded 방법에 난 그냥 변경 layoutSubviews : layoutIfNeeded에 대한 애플의 문서에서

+ (CGFloat)heightForEditorialCommentData:(EditorialCommentVMData *)editorialData 
{ 
    EditorialCommentCell * cell = [EditorialCommentCell instanceCell]; 
    [cell applyViewModelData:editorialData]; 
    [cell layoutIfNeeded]; 
    return cell.commentTextLabel.frameBottom + kTextInsets.bottom; 
} 

:

이 방법을 사용 그리기 전에 파단의 레이아웃을 강제로. 메시지를 루트보기로받는보기 을 사용하면이 방법은 을 루트에서 시작하는 뷰 하위 트리에 배치합니다.

관련 문제