开发者

Selector problem

I must have misunderstood something. I simply want to use performSelector: to call one of my own methods. Here I have the method declaration in the @interface:

-(void)forceReload;

FYI, all of this code is defined on only one type. And here is the method implementation and the calling method:

-(开发者_StackOverflowvoid)forceReload {
    // code here...
}

-(void)entryActivityEditViewControllerDidFinish {

    // etc...

    DebugLog(@"self=%@", self);
    DebugLog(@"responds to selector=%@", [self respondsToSelector:@selector(forceReload:)] ? @"true" : @"false");
    [self forceReload]; // Works fine
    [self performSelector:@selector(forceReload:)]; // unrecognized selector
}

What confounds me is that I can send the message directly to the object but it fails when used with performSelector:. Should success with the former imply success with the latter?

And to round it out, here's some debug spew showing that my target object (self) is the very type I think it is and that I'm sending to the appropriate object. I also included a call to respondsToSelector: and found that my object does not respond to forceReload: which confounds me yet more. Why would this be?

0x1006030/-[EntryActivityTableViewController entryActivityEditViewControllerDidFinish] (EntryActivityTableViewController.m:236): self=<EntryActivityTableViewController: 0x1259160>
0x1006030/-[EntryActivityTableViewController entryActivityEditViewControllerDidFinish] (EntryActivityTableViewController.m:237): responds to selector=false
2009-12-20 10:22:44.999 Workouts[407:207] *** -[EntryActivityTableViewController forceReload:]: unrecognized selector sent to instance 0x1259160
2009-12-20 10:22:45.017 Workouts[407:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[EntryActivityTableViewController forceReload:]: unrecognized selector sent to instance 0x1259160'

Please tell me where my understanding is wrong. :-)


Your method takes no arguments, but your @selector() call requests a selector that takes one argument. What you want is this:

[self performSelector:@selector(forceReload)]; // unrecognized selector
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜