开发者

Why is perform:withObject method not found?

I want to fix warnings in my application code. I have an AddressBookModel.h which implements the TTModel protocol.

You find both interface and implementation of the AdressBookModel in the answer of this question. This is exactly how I implemented it How to use Three20 TTMessageController?

However for

[_delegate开发者_JS百科s perform:@selector(modelDidStartLoad:) withObject:self];

and some other similar selectors I get warnings like

Method -perform:withObject not found (return type defaults to id)

Since _delegates is an array

- (NSMutableArray*)delegates {
    if (!_delegates) {
        _delegates = TTCreateNonRetainingArray();
    }
    return _delegates;
}

some suggested to use makeObjectsPerformSelector but this gives me an unrecognized selector sent to instance exception.

Here is the TTModel source code: http://api.three20.info/protocol_t_t_model-p.php

Why is perform:withObject missing? Is performSelector:withObject an alternative (my app crashes using it)?


_delegates is an array of delegates. It is not a true delegate, as signified from the name which is in plural form. An array does not respond to the -modelDidFinishLoad: method — its elements do.

You need to take each element out of the array and call the method of them, e.g.

for (id<TTModelDelegate> delegate in _delegates)
   [delegate modelDidFinishLoad:self];

or even easier, using NSArray's -makeObjectsPerformSelector:…:

[_delegates makeObjectsPerformSelector:@selector(modelDidFinishLoad:)
                            withObject:self];


perform:withObject: method that produces this warning is defined in NSArray(TTCategory) category in NSArrayAdditions.h file in Three20 framework. You need to ensure that this header is imported/referenced properly by compiler, i.e. you need to look at importing this specific header or check your Three20 integration configuration.

You do not need to change this method to makeObjectsPerformSelector: since this is just an import problem (your code runs fine but just produces compile warnings).


Reading between the lines, it looks like you want the objects that are in your _delegates array to all perform a particular selector. You need to call -makeObjectsPerformSelector:withObject: like this:

[_delegates makeObjectsPerformSelector: @selector(modelDidCancelLoad:) withObject: self];


You are mistyping modelDidCancleLoad: should be modelDidCancelLoad:

'NSInvalidArgumentException', reason:
'-[__NSCFArray modelDidCancleLoad:]: unrecognized selector
 sent to instance 0x24f480'

Make sure your _delegates is what you are expecting it to be. It seems to be an NSArray.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜