2014-06-16 4 views
0
- (CGSize)sizeOfLabel:(UILabel *)label withText:(NSString *)text { 
    CGSize maximumLabelSize = CGSizeMake(308,9999); 
    UIFont *font=[UIFont systemFontOfSize:14]; 
    CGRect textRect = [text boundingRectWithSize:maximumLabelSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil]; // CRASH HERE 
    return textRect.size; 
} 


**the error message is:** 

2014-06-16 14:55:07.783 OrgBeac[2931:60b] -[Message boundingRectWithSize:options:attributes:context:]: unrecognized selector sent to instance 0x17557a70 
2014-06-16 14:55:07.787 OrgBeac[2931:60b] \*\*\* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Message boundingRectWithSize:options:attributes:context:]: unrecognized selector sent to instance 0x17557a70' 
\*\*\* First throw call stack: 
(0x2e6f4fd3 0x38f6dccf 0x2e6f8967 0x2e6f7253 0x2e6f84f8 0x575d5 0x579e7 0x31020a2b 0x30fe569f 0x30fe73fd 0x30fe7351 0x30fe6f45 0x56f37 0x2f0e56d1 0x39324cef 0x393222ad 0x39321319 0x2f0e3cb9 0x2f0e3f41 0x2f0e40b7 0x2f0e41b5 0x5674d 0x2f033fc3 0x2f033f07 0x2f033e21 0x2e35b0e7 0x2e359cf7 0x2e628941 0x2e2f16bb 0x2e2f1579 0x2e2f140d 0x2e6c025b 0x2e6bf72b 0x2e6bdf1f 0x2e628f0f 0x2e628cf3 0x33581663 0x30f7416d 0x55283 0x3947aab7) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
+2

그것은 나를 위해 작동 내가 만든 빠른 테스트 앱에서. 텍스트로 전달할 내용을 확인하십시오. NSString이 아닐 수도 있습니다. –

+1

당신은'UILabel' 객체 대신'Message'를 전달하고 있습니다. –

+0

고맙습니다. 이것이 문제였습니다. –

답변

0

전달할 객체 textNSString이어야하지만 Message 개체 여야합니다. 사실 당신이 무엇을 의미하는지 나는 당신이 당신에게서이를 호출하는 모든 곳에서 같은 일을하고 있다는 것을 추측하고있어

...

[someObject sizeOfLabel:myLabel withText:message]; 

은 ...

[someObject sizeOfLabel:myLabel withText:message.text];