objc_msgSend (xcode)

来源:互联网 发布:福建卓知咨询有限公司 编辑:程序博客网 时间:2024/05/16 01:35
Generally what this means is that you're sending a message (calling a method) on an object that you has been freed. Most likely, you got an object back from an class method, like

NSString *myString = [NSString stringWithString:@\"Foo\"];


and you didn't retain it. If you are using Objective-C 2.0 properties, then you want to specify your properties as retain, and you want to use the mutator (setter) and do not want to assign values to your instance variables directly. So, if it were a string, you'd want to make sure you declared it like:

@property (retain) NSString *myString;


and then when you use it, make sure to call
self.myString = (value returned from class method)


or

[self setMyString:(value returned from class method)];


If it's not something you're storing in an instance variable, then it could be any number of things, hard to say exactly without seeing the code, but basically, look for values returned from class methods that you need to stick around, and then make sure it's either being assigned to a property using the mutator method or dot notation, or make sure you are retaining it.

You should be able to figure out which object it is trying to send a message to by running in the debugger, then when it crashes, move up the call trace in the debugger until you get to your code - that should be the line of code where it crashed.


最后发现

if (parent && [parentrespondsToSelector:@selector(changeToPage:name:)] ==YES

发送消息的parent 已经释放了。