甚至為了performance,所有的加載操作都在后臺完成,一定要重用:

網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、小程序定制開發(fā)、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了淮陰免費建站歡迎大家使用!
在iOS開發(fā)中利用GCD進行多線程編程
iOS開發(fā)中使用NSOperationQueue進行多線程操作
避免后臺加載完成多個資源之后集中到達占用UI線程的處理時間太長。
這一點可以通過dispatch或者performSelectorInBackground或者NSOperationQueue來實現(xiàn)。
創(chuàng)建cell一般是很慢的。
重用cell解決辦法
主要要做到一下幾個方面,且在每個操作完成之后進行強制等待。
這一點可以通過NSOperationQueue來實現(xiàn)。見:
除了UI部分,可以用usleep(int microSeconds)來解決,將資源到UI的展現(xiàn)過程放在隊列中逐個執(zhí)行,可以在view創(chuàng)建之初就創(chuàng)建足夠多的cell在重用隊列中
,然后把兩個MBProgressHUD.h和MBProgressHUD.m放到自己的項目就可以了。這里有一個小Demo可以參考一下。
頭文件部分:
#import UIKit/UIKit.h#import "MBProgressHUD.h"@interface ViewController : UIViewController{ MBProgressHUD *HUD;}- (IBAction)showTextDialog:(id)sender; //文本提示框,默認情況下- (IBAction)showProgressOne:(id)sender; //第一種加載提示框- (IBAction)showProgressTwo:(id)sender; //第二種加載提示框- (IBAction)showProgressThree:(id)sender; //第三種加載提示框- (IBAction)showCustomDialog:(id)sender; //自定義提示框,顯示打鉤效果- (IBAction)showAllTextDialog:(id)sender; //顯示純文本提示框@end
實現(xiàn)文件部分
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}- (IBAction)showTextDialog:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD]; HUD.dimBackground = YES; //把當前的view置于后臺 HUD.labelText = @"請稍等"; //顯示對話框 [HUD showAnimated:YES whileExecutingBlock:^{ sleep(3); } completionBlock:^{ }];}- (IBAction)showProgressOne:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD]; HUD.labelText = @"正在加載"; HUD.mode = MBProgressHUDModeDeterminate; //HUD.mode = MBProgressHUDModeAnnularDeterminate; [HUD showAnimated:YES whileExecutingBlock:^{ float progress = 0.0f; while (progress 1.0f) { progress += 0.01f; HUD.progress = progress; usleep(5000); } } completionBlock:^{ [HUD removeFromSuperview]; [HUD release]; HUD = nil; }];}- (IBAction)showProgressTwo:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD]; HUD.labelText = @"正在加載"; HUD.mode = HUD.mode = MBProgressHUDModeAnnularDeterminate; [HUD showAnimated:YES whileExecutingBlock:^{ float progress = 0.0f; while (progress 1.0f) { progress += 0.01f; HUD.progress = progress; usleep(5000); } } completionBlock:^{ [HUD removeFromSuperview]; [HUD release]; HUD = nil; }];}- (IBAction)showProgressThree:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD]; HUD.labelText = @"正在加載"; HUD.mode = MBProgressHUDModeDeterminateHorizontalBar; [HUD showAnimated:YES whileExecutingBlock:^{ float progress = 0.0f; while (progress 1.0f) { progress += 0.01f; HUD.progress = progress; usleep(5000); } } completionBlock:^{ [HUD removeFromSuperview]; [HUD release]; HUD = nil; }];}- (IBAction)showCustomDialog:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD]; HUD.labelText = @"操作成功"; HUD.mode = MBProgressHUDModeCustomView; HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Checkmark"]] autorelease]; [HUD showAnimated:YES whileExecutingBlock:^{ sleep(2); } completionBlock:^{ [HUD removeFromSuperview]; [HUD release]; HUD = nil; }];}- (IBAction)showAllTextDialog:(id)sender { HUD = [[MBProgressHUD alloc] initWithView:self.view]; [self.view addSubview:HUD]; HUD.labelText = @"操作成功"; HUD.mode = MBProgressHUDModeText; HUD.customView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Checkmark"]] autorelease]; [HUD showAnimated:YES whileExecutingBlock:^{ sleep(2); } completionBlock:^{ [HUD removeFromSuperview]; [HUD release]; HUD = nil; }]; }- (void)dealloc { [super dealloc];}@end
當前名稱:ios開發(fā)usleep,IOS開發(fā)者模式
URL網(wǎng)址:http://chinadenli.net/article7/dsehpij.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設、外貿(mào)網(wǎng)站建設、App設計、企業(yè)建站、品牌網(wǎng)站制作、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)