子线程中无法刷新更新 UI
2014-11-26 13:41
148 查看
显示结果:
// // RootViewController.m // 多线程- // // Created by zm on 14-11-26. // Copyright (c) 2014年 practice. All rights reserved. // #import "RootViewController.h" @interface RootViewController ()<NSURLConnectionDataDelegate> { UIProgressView *_progressView; } @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { } return self; } /** * 测试子线程更新 UI * 唯一的情况只能是,子线程执行完毕,主线程中的值发生改变,主线程最终刷新改变 UI * 现在的iOS版本,子线程中刷新界面的操作有时可能成功,已经部分支持了。但官方文档规定是主线程负责 UI 刷新界面 */ -(void)testNSTreadFreshUI { _progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 100, 320, 44)]; [self.view addSubview:_progressView]; [self performSelectorInBackground:@selector(testNSTreadProgress) withObject:nil]; } -(void)testNSTreadProgress { int progress = 0; for (int i = 0; i < 1000; i++) { progress += i; [NSThread sleepForTimeInterval:0.1]; _progressView.progress = progress/1000.f; } } - (void)viewDidLoad { [super viewDidLoad]; [self testNSTreadFreshUI]; } @end
相关文章推荐
- elementui select组件选中后无法自动刷新更新值渲染到页面中
- 子线程真的无法更新UI吗?
- Python2.7+mysqlDB+mysql5.5.x更新操作无法正常刷新到服务器的问题
- android 使用Handler UI线程和子线程通讯 更新UI
- Android开发之——子线程中使用Toast或者更新UI
- Android—子线程更新UI问题( java.lang.RuntimeException: Can't create handler inside thread that has not cal)
- Android 中确定子线程不能更新UI吗?
- android中的UI视图更新不能放在子线程中操作
- 子线程真的不能更新UI吗?
- 子线程一定不能更新UI吗?
- iOS实战-头像更新上传之后,UI不刷新
- VS无法正常加载Wpf后台刷新ui的自定义控件
- listview分页加载刷新——--填充数据,适配器更新与UI同步更新问题
- jQueryUI Repeater 无刷新删除 新建 更新数据 - JQueryElement [7]
- Android:UI更新方法四:在Worker Thread中runOnUiThread直接刷新UI
- 为什么子线程不能更新UI的完全解析!!
- 一个奇怪的子线程更新UI问题
- python3多线程更新UI数据,pyqt5界面刷新
- 这是子线程在更新UI吗?????
- Android能否在子线程中更新UI呢?