无法在performSelectorInBackground中调用实例方法

时间:2014-03-20 05:13:59

标签: ios iphone objective-c

我有一个MatchDayDataController类,它有一个方法pushIncompleteDataToServer。

来自另一个类,SummaryVC.m我想在performSelectorInBackground中调用pushIncompleteDataToServer。

代码:

 MatchDayDataController *sharedDataController = [MatchDayDataController sharedDataController];
        [self performSelectorInBackground:@selector([sharedDataController pushIncompleteDataToServer]) withObject:nil];

它在performSelectorInBackground中显示了一些语法错误。我错过了什么?请指导。

3 个答案:

答案 0 :(得分:3)

[self performSelectorInBackground:@selector([sharedDataController pushIncompleteDataToServer]) withObject:nil];

这将使代码在同一个类中搜索该方法

应该是:

[sharedDataController performSelectorInBackground:@selector(pushIncompleteDataToServer) withObject:nil];

会调用sharedDataController

中的方法

此外,在方法performSelectorInBackground: withObject:中, withObject 用于将参数传递给选择器方法。在这种情况下,由于没有参数,我们传递nil。

答案 1 :(得分:0)

试试这个,

[sharedDataController performSelectorInBackground:@selector(pushIncompleteDataToServer) withObject:nil];

而不是

[self performSelectorInBackground:@selector([sharedDataController pushIncompleteDataToServer]) withObject:nil];

答案 2 :(得分:0)

您需要将self替换为sharedDataController

[sharedDataController performSelectorInBackground:@selector(pushIncompleteDataToServer) withObject:nil];

选择器将在performSelectorInBackground消息的接收者上执行,self不实现该方法。