草庐IT

dispatch_source_cancel

全部标签

ios - iOS 中的 JSON 请求 - 使用 Grand Central Dispatch 或 NSURLConnection

我看到了一些关于在iOS中发出JSON请求的教程,其中许多使用NSURLConnection列出了类似这样的内容:-(void)connection:(NSURLConnection*)connectiondidReceiveResponse:(NSURLResponse*)response{[self.responseDatasetLength:0];}-(void)connection:(NSURLConnection*)connectiondidReceiveData:(NSData*)data{[self.responseDataappendData:data];}-(void

ios - NSOperationQueue : cancel an operation after a timeout given

基本上,如果我添加到队列的操作在特定超时后没有响应,我想执行取消:NSOperationQueue*queue=...[self.queueaddOperationWithBlock:^{//myblock...}timeoutInSeconds:5.0hasTimedOutWithBlock:^{//calledafter5.0,operationshouldbecanceledattheend}];谢谢大家! 最佳答案 你可以按照你的要求做一些事情,但我可能建议向第一个block添加一个参数,第一个block可以通过该参数检查操

ios - 什么是 dispatch_queue_create 中的队列属性

在Apple的示例代码中,AVCam-iOS:UsingAVFoundationtoCaptureImagesandMovies,我注意到以下一行://Communicatewiththesessionandothersessionobjectsonthisqueue.self.sessionQueue=dispatch_queue_create("sessionqueue",DISPATCH_QUEUE_SERIAL);我想知道第二个参数是关于什么的,除了DISPATCH_QUEUE_SERIAL我们还有哪些其他选项?令人困惑的是,在其他Apple文档中,它说第二个参数是保留的,应该

ios - UIAlertViewController : Separate tint colors for cancel and other action buttons

是否可以为取消和其他操作按钮提供单独的色调颜色?目前我正在将色调颜色更改为controller.view.tintColor=[UIColorblackColor];但它也改变了取消按钮的色调。我需要为取消按钮设置不同的色调颜色,比如红色。请帮帮我。 最佳答案 按如下方式设置警报操作的颜色:UIAlertAction*cancel=[UIAlertActionactionWithTitle:@"Cancel"....[cancelsetValue:[UIColorredColor]forKey:@"titleTextColor"];

ios - 当方法重新运行时,在方法中循环 dispatch_after 会导致许多同时调度

我正在创建一个简单的游戏。我有以下代码:-(void)doStuff{doubledelayInSeconds=[NSNumberrandomFloatBetweenLowerBound:0.8fupperBound:2.6f];//OwncategoryonNSNumberreturnsrandomfloat.dispatch_time_tpopTime=dispatch_time(DISPATCH_TIME_NOW,(int64_t)(delayInSeconds*NSEC_PER_SEC));dispatch_after(popTime,dispatch_get_main_que

ios - 在 dispatch_once(&onceToken, ^{

+(Service*)sharedInstance{staticLocationService*instance=nil;staticdispatch_once_tonceToken;dispatch_once(&onceToken,^{我正在使用上面显示的代码在我的应用程序中创建服务的单例实例。这是从“AppDelegateapplication:willFinishLaunchingWithOptions:”调用的。对于大多数用户来说,这段代码工作正常。但是对于2个用户,应用程序在“dispatch_once(&onceToken,^{”行崩溃。他们删除了该应用程序并重新安装了它。

iphone - 这段代码中dispatch_after方法是并发执行的吗?

inttotal=0;//theseareglobals..BOOLdispatchCalled=NO;//-(void)callDispatch{dispatch_after(dispatch_time(DISPATCH_TIME_NOW,0.3*NSEC_PER_SEC),dispatch_get_current_queue(),^{dispatchCalled=YES;NSLog(@"Total,after300ms,is%i",total);});}-(void)play//thisismy"main"method..{NSLog(@"appstartsrunning");[s

iOS TableView 滞后问题,我正在使用分派(dispatch)和保存缓存

-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath{TableViewCell*cell=[tableViewdequeueReusableCellWithIdentifier:@"TableViewCell"forIndexPath:indexPath];cell.tag=indexPath.row;//cell.imageView.image=nil;//RoundedRectforcellimageCALayer*cellImageLay

ios - 为什么-tableView :heightForRowAtIndexPath: is a delegate method instead of a data source method?

这个问题在这里已经有了答案:DifferencebetweenUITableViewDelegateandUITableViewDatasource(4个答案)关闭6年前。我发现这个方法是一个UITableView委托(delegate)方法:-(CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath*)indexPath{return20;}我真的很困惑,为什么它不是数据源方法?

iphone - 使用图层和 Grand Central Dispatch 渲染 UIButtons 的最快方法?

我有一个包含30个UIButton的网格,甚至可能更多,它们被子类化以使用层进行渲染:一个基本CALayer、一个CAShapeLayer、一个CAGradientLayer和一个CATextLayer。我试图在加载相应的xib文件时尽量减少渲染/显示按钮所需的总时间。如果我在viewDidLoad中简单地依次设置每个按钮,View出现所需的时间大约为5-6秒,这显然太多了。为了加快按钮设置速度,我按如下方式使用GrandCentralDispatch。在viewDidLoad中,我在全局队列上使用dispatch_async设置每个按钮层(将形状层和渐变层添加到基础层),以便按钮可以