ios detachNewThreadSelector, how to withObjects?
I know that
detachNewThreadSelector:toTarget:withObject
can have a (id)anArgument. I have searched it that it can work for NSString. 开发者_StackOverflow社区
However, when I pass an integer or size_t, it crashed. Can somebody tell me what is (id)anArgument?
What's more, how can I pass more than one parameter to the thread? For example, I have a function,
-(NSInteger)getIneger: (NSInteger) pageNumber withName(NSString*) filename ;
something like that. Thanks
What (id)anArgument
tells you is that you need to pass an Objective-C argument. Since neither integer nor size_t are Objective-C objects, the application crashes. You will need to package them within an NSNumber
for this to work. You will also have to alter the method to take in an NSNumber
rather than the int
. To pass two or more arguments, I suggest you use an NSDictionary
object to pass values based on keys. You can define a method that takes in an NSDictionary
object, unpacks the values and calls the original method you had intended to call.
精彩评论