我的应用程序崩溃是的getJSON功能可按看起来像: - (void)getJSON: (NSDate *)startTime endTime:(NSDate *)endTime;
问题的NSThreads在这条线 <code>[NSThread detachNewThreadSelector: @selector(getJSON:) toTarget:self withObject:nil];</code></p> <p>这里
它有什么问题?
我的应用程序崩溃是的getJSON功能可按看起来像: - (void)getJSON: (NSDate *)startTime endTime:(NSDate *)endTime;
问题的NSThreads在这条线 <code>[NSThread detachNewThreadSelector: @selector(getJSON:) toTarget:self withObject:nil];</code></p> <p>这里
它有什么问题?
它看起来像你没有正确指定方法;每个参数是方法名称的一部分:
[NSThread detachNewThreadSelector:@selector(getJSON:endTime:)
toTarget:self
withObject:nil];
为- (void)getJSON:(NSDate *)startTime endTime:(NSDate *)endTime
的选择是
@selector(getJSON:endTime:)
虽然你们是正确的,方法选择是错误的,你的解决方案不会帮助,因为选择了detachNewThreadSelector必须只有一个参数。
withObject参数将作为唯一参数传递给您的线程方法。
如果螺纹方法希望接收的开始和结束时间,然后按正常方式做到这一点是有一个NSDictionary,是这样的:
[NSThread detachNewThreadSelector:@selector(getJSON:)
toTarget:self
withObject:[NSDictionary dictionaryWithObjectsAndKeys:
startTime, @"startTime",
endTime, @"endTime",
nil]];
那么线程的方法是
- (void) getJSON: (NSDictionary*) parameters
{
NSDate* startTime = [parameters objectForKey:@"startTime"];
NSDate* endTime = [parameters objectForKey:@"endTime"];
...
}
正确的一个。谢谢 – Mladen 2009-06-05 12:16:41