相关疑难解决方法(0)

Cocoa @selector用法的解释

我是Cocoa/Cocoa Touch的新手,并且正在编写一本开发手册.我遇到过使用@selector()运算符的情况.关于如何以及何时应该使用@selector()运算符,我有点迷失.有人可以提供一个简短而甜蜜的解释,说明为什么使用它以及它给开发人员带来了什么好处?

顺便说一下,这里是从Apple的iPhone开发站点获取的示例代码,它使用@selector()

if ([elementName isEqualToString:@"entry"])
{

    parsedEarthquakesCounter++;

    // An entry in the RSS feed represents an earthquake, so create an instance of it.
    self.currentEarthquakeObject = [[Earthquake alloc] init];
    // Add the new Earthquake object to the application's array of earthquakes.
    [(id)[[UIApplication sharedApplication] delegate]
            performSelectorOnMainThread:@selector(addToEarthquakeList:)
            withObject:self.currentEarthquakeObject waitUntilDone:YES];
    return;
}
Run Code Online (Sandbox Code Playgroud)

objective-c

24
推荐指数
1
解决办法
3万
查看次数

标签 统计

objective-c ×1