- 浏览: 698540 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
javenwong:
你好,我现在需要给一个Composite做圆角处理,不知道怎么 ...
SWT圆角窗口绘制 -
whao189:
回家了详细看看
Storyboard 解析 -
zhaoyubetter:
确实够麻烦
IOS 开发环境,证书和授权文件是什么? -
datawarehouse:
一直对这两个认为是一样的,现在学习了。
Oracle DB中的Schema -
yulanfeiyang:
顶,mark
下载音频,在IOS设备上播放
举例说明怎么简单的创建一个子线程。 用到的类是NSThread类,这里使用detachNewTheadSelector:toTagaet:withObject创建一个线程。 函数setupThread:(NSArray*)userInfor。通过userInfor将需要的数据传到线程中。 函数定义: -(void)setupThread:(NSArray*)userInfor{ [NSThread detachNewThreadSelector:@selector(threadFunc:) toTarget:self withObject:(id)userInfor]; } - (void)threadFunc:(id)userInfor{ NSAutoreleasePool*pool = [[NSAutoreleasePool alloc] init]; //。。。。需要做的处理。 //这里线程结束后立即返回 [self performSelectorOnMainThread:@selector(endThread) withObject:nil waitUntilDone:NO]; [pool release]; } performSelectorOnMainThread通知主线程执行函数endThread。也可以使用performSelector:onThread:withObject:waitUntil 通知某线程执行线程结束后的处理。 线程内不要刷新界面。如果需要刷新界面,通过performSelectorOnMainThread,调出主线程中的方法去刷新。 例如,启动一个线程下载图片: //启动线程 [NSThread detachNewThreadSelector:@selector(downloadImage:) toTarget:self withObject:url]; //线程函数 - (void) downloadImage:(NSString*)url{ _subThreed = [NSThread currentThread]; self.uploadPool = [[NSAutoreleasePool alloc] init]; self.characterBuffer = [NSMutableData data]; done = NO; [[NSURLCache sharedURLCache] removeAllCachedResponses]; NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURLURLWithString:url]]; self.connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; [self performSelectorOnMainThread:@selector(httpConnectStart) withObject:nil waitUntilDone:NO]; if (connection != nil) { do { [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; } while (!done); } self.photo = [UIImage imageWithData:characterBuffer]; //下载结束,刷新 [self performSelectorOnMainThread:@selector(fillPhoto) withObject:nil waitUntilDone:NO]; // Release resources used only in this thread. self.connection = nil; [uploadPool release]; self.uploadPool = nil; _subThreed = nil; } #pragma mark NSURLConnection Delegate methods /* Disable caching so that each time we run this app we are starting with a clean slate. You may not want to do this in your application. */ - (NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse { return nil; } // Forward errors to the delegate. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { done = YES; [self performSelectorOnMainThread:@selector(httpConnectEnd) withObject:nil waitUntilDone:NO]; [characterBuffer setLength:0]; } // Called when a chunk of data has been downloaded. - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { // Process the downloaded chunk of data. [characterBuffer appendData:data]; } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { [self performSelectorOnMainThread:@selector(httpConnectEnd) withObject:nil waitUntilDone:NO]; // Set the condition which ends the run loop. done = YES; }
发表评论
-
iphone编程之UILabel 用法详解
2012-12-18 14:38 1353这段代码动态的创建了一个UILabel,并且把相关常用的属 ... -
IOS用正则验证手机号
2012-12-14 12:01 17149- (BOOL)validateMobile:(NSStr ... -
UITableView技巧之去除UITableViewCell边框
2012-12-14 10:42 3557有时候想在UITableViewCell中加内容,但又不想要c ... -
MAC MySQL Workbench执行批量更新和删除的时候错误解决
2012-10-25 11:21 3954处理MySQL更新表时ErrorCode:1175.You a ... -
Objective-C编码风格指南
2012-10-17 17:00 1155参考资料: • Apple: Coding Guideline ... -
autorelease对象具体什么时候释放?
2012-09-19 15:21 996在项目中,会有一个默认的Autorelease pool,程序 ... -
Objective-C内存管理教程和原理剖析
2012-09-10 14:44 854此文涉及的内存管理是针对于继承于NSObject的Clas ... -
IOS开发内存释放小结
2012-09-03 17:34 5308内存释放是iphone开发过程中比较重的地方,所以在开辟内存后 ... -
为什么Android没有iOS那么顺滑
2012-08-29 14:38 861虽然很多Android手机的配 ... -
UITextView关闭键盘
2012-08-29 14:13 141461.如果你程序是有导航条的,可以在导航条上面加多一个Done的 ... -
Mac系统下查看鼠标所在点的RGB值--数码测色计
2012-08-29 14:05 1744苹果电脑的Mac OS X系统自带鼠标所在点颜色RGB值查看工 ... -
UIView你知道多少
2012-08-21 09:49 780曾经有人这么说过,在i ... -
Objective-C内存管理总结〜CC专版
2012-08-17 18:24 752iPhone系统中的Objective-C的内存管理机制是比较 ... -
iOS内存管理
2012-08-17 18:19 27941. 内总管理原则(引用计数) IOS的对象都继承于 ... -
IOS 获取当前系统时间的年、月、日、小时、分、秒
2012-08-14 17:33 6551NSCalendar *calendar = [[NSCa ... -
IOS判断是否为数字
2012-08-13 17:59 4854判断是否为整形: - (BOOL)isPureInt:(N ... -
self.用法
2012-08-09 14:55 812MyClass.h @interface MyClass ... -
#import与@class的区别
2012-08-08 17:13 8951.import会包含这个类的所有信息,包括实体变量和方法,而 ... -
iphone图标去掉光晕效果
2012-08-07 16:53 1111图片背景是透明的 如果想去掉光晕效果,就在info.plist ... -
去掉 App Store 内图标上部高亮效果的办法
2012-08-07 16:52 842苹果默认会在 App Store 里的应用图标上半部自 ...
相关推荐
OC-detachNewThreadSelector
ios demo,主队列,异步调度,手动创建线程,detachNewThreadSelector dispatch_get_main_queue
2.请问关键字 alloc 和 init 的 区别 alloc是分配内存,对象计数器为1 init是初始化工作 类似于c++构造函数 3. 请问 property 的 作用,assign,copy,retain 的 区别; assign就是基本赋值 copy是重新创建一个...
//initWithNibName将控制器绑定xib的方法,如果xib的名称和控制器的类名称相同的时候,直接写init(会自动绑定同名的xib)就可以,如果xib的名称和类名称不同的话,必须手动调用此方法来进行绑定 ...
> [NSThread detachNewThreadSelector:@selector(runJobs:) > toTarget:self > withObject:parameters]; > } > > //wait until done, ie until the count of threads in threadLock is > down to 0 > > [threadLock...
[NSThread detachNewThreadSelector:@selector(doSomething:) toTarget:self withObject:@oneClick]; } -(void)doSomething:(NSString*) str{ NSLog(@%@,str); } - (void)twoClick{ NSThread* myThread = [...