为什么在boundingRectWithSize崩溃这段代码?

时间:2014-06-16 12:01:27

标签: objective-c ios7 xcode5 nsexception

- (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

1 个答案:

答案 0 :(得分:0)

您传入的对象text必须是NSString,但它是Message对象。

我猜你无论在哪里打电话给你都在做......

[someObject sizeOfLabel:myLabel withText:message];

实际上你的意思是......

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