我有这个方法,我打电话,一切都很好:
的DataHandler:
.h:
-(void)saveNumberOfTries:(NSString*)numberOfTries toWord:(NSString *)indexOfWord;
.m:
-(void)saveNumberOfTries:(NSString*)numberOfTries toWord:(NSString *)indexOfWord {...}
ViewController.m
DataHandler *dataHandler = [[DataHandler alloc] init];
[dataHandler performSelector:@selector(saveNumberOfTries:toWord:) withObject:numberOfTries withObject:wordId];
..然后我更新了它再拿一个论点:
的DataHandler:
.h:
-(void)saveNumberOfTries:(NSString*)numberOfTries toWord:(NSString *)indexOfWord currentLevel:(NSString*)userSelectedLevel;
.m:
-(void)saveNumberOfTries:(NSString*)numberOfTries toWord:(NSString *)indexOfWord currentLevel:(NSString*)userSelectedLevel {...}
ViewController.m:
DataHandler *dataHandler = [[DataHandler alloc] init];
[dataHandler performSelector:@selector(saveNumberOfTries:toWord:currentLevel:) withObject:numberOfTries withObject:wordId withObject:selectedLevel];
但是编译器现在给我“接收器类型'DataHandler'例如消息没有声明一个带有选择器的方法'performSelector:withObject:withObject:withObject:'”。
如果我输入原始方法调用(不更改DataHandler中的任何内容),虽然该方法不再存在,但它不会给我任何警告。似乎Xcode没有跟上我的变化。任何想法或建议?
答案 0 :(得分:0)
因为没有类似performSelector:withObject:withObject:withObject:
您可以压缩为NSArray
或NSDictionary
,然后使用performSelector:withObject:withObject:
就像你的情况一样 -
-(void)saveNumberOfTries:(NSString*)numberOfTries toWordWithCurrentLevel:(NSDictionary *)wordAndLevel;
其他方式,如果你不想改变方法的定义,你可以尝试下面然后它会工作正常 -
[dataHandler saveNumberOfTries:numberOfTries toWord:wordId currentLevel:selectedLevel];