alertView不能自动隐藏——谈多线程执行延迟对应用程序的影响
当CommonAlert.m中的方法执行的快时,alertView的显示和消失是正常的。如下所示:
2013-01-24 23:31:59.978 点餐系统[5649:707] 进入OrderListViewController.m的-(IBAction)btnTaocanMenuClicked:(id)sender
2013-01-24 23:31:59.982 点餐系统[5649:707] 进入CommonAlert.m的startAlertView
2013-01-24 23:31:59.986 点餐系统[5649:5e0b] 进入CommonAlert.m的startAlertProcess
2013-01-24 23:31:59.989 点餐系统[5649:5f07] 进入CommonAlert.m的presentAlert
2013-01-24 23:31:59.995 点餐系统[5649:707] 进入OrderListViewController.m的-(void)ShowOrderMenu
2013-01-24 23:31:59.997 点餐系统[5649:707] 进入OrderListViewController.m的-(void)clearSmallOrderList:(NSString *)code
2013-01-24 23:32:00.003 点餐系统[5649:707] 进入OrderListViewController.m的-(void)getFoodByType:(NSString *)typeCode Type:(NSInteger) type PackageId:(NSString *)packageid
2013-01-24 23:32:00.042 点餐系统[5649:5f07] 进入JKCustomAlert.m的- (void) show
2013-01-24 23:32:00.054 点餐系统[5649:5f07] 进入JKCustomAlert.m的- (void) layoutSubviews
2013-01-24 23:32:00.063 点餐系统[5649:5f07] 进入JKCustomAlert.m的- (void) layoutSubviews
2013-01-24 23:32:00.066 点餐系统[5649:5f07] 进入JKCustomAlert.m的- (void)drawRect:(CGRect)rect
2013-01-24 23:32:00.085 点餐系统[5649:707] 进入OrderListViewController.m的-(void)parserTaocan:(NSMutableArray *)foodlist
2013-01-24 23:32:00.089 点餐系统[5649:707] smallPic:
2013-01-24 23:32:00.093 点餐系统[5649:707] 进入OrderListViewController.m的-(NSString *)documentsFolder
2013-01-24 23:32:00.101 点餐系统[5649:707] smallPic:
2013-01-24 23:32:00.105 点餐系统[5649:707] 进入OrderListViewController.m的-(NSString *)documentsFolder
2013-01-24 23:32:00.134 点餐系统[5649:707] smallPic:
2013-01-24 23:32:00.137 点餐系统[5649:707] 进入OrderListViewController.m的-(NSString *)documentsFolder
2013-01-24 23:32:00.148 点餐系统[5649:707] 进入OrderListViewController.m的-(void)animationOglFlip
2013-01-24 23:32:00.151 点餐系统[5649:707] 进入CommonAlert.m的dismissAlertView
2013-01-24 23:32:00.739 点餐系统[5649:707] 进入JKCustomAlert.m的- (void)dealloc
当CommonAlert.m中的方法执行的慢时,alertView的就无法正常消失。因为,当我们调用dismissAlertView方法时,alertView还没有绘制出来呢!而当alertView绘制出来时,dismissAlertView方法早已错过。
2013-01-24 23:35:03.687 点餐系统[5649:707] 进入OrderListViewController.m的-(IBAction)btnTaocanMenuClicked:(id)sender
2013-01-24 23:35:03.690 点餐系统[5649:707] 进入CommonAlert.m的startAlertView
2013-01-24 23:35:03.693 点餐系统[5649:442f] 进入CommonAlert.m的startAlertProcess
2013-01-24 23:35:03.696 点餐系统[5649:690f] 进入CommonAlert.m的presentAlert
2013-01-24 23:35:03.702 点餐系统[5649:707] 进入OrderListViewController.m的-(void)ShowOrderMenu
2013-01-24 23:35:03.704 点餐系统[5649:707] 进入OrderListViewController.m的-(void)clearSmallOrderList:(NSString *)code
2013-01-24 23:35:03.709 点餐系统[5649:707] 进入OrderListViewController.m的-(void)getFoodByType:(NSString *)typeCode Type:(NSInteger) type PackageId:(NSString *)packageid
2013-01-24 23:35:03.746 点餐系统[5649:707] 进入OrderListViewController.m的-(void)parserTaocan:(NSMutableArray *)foodlist
2013-01-24 23:35:03.748 点餐系统[5649:707] smallPic:
2013-01-24 23:35:03.751 点餐系统[5649:707] 进入OrderListViewController.m的-(NSString *)documentsFolder
2013-01-24 23:35:03.759 点餐系统[5649:707] smallPic:
2013-01-24 23:35:03.763 点餐系统[5649:707] 进入OrderListViewController.m的-(NSString *)documentsFolder
2013-01-24 23:35:03.770 点餐系统[5649:707] smallPic:
2013-01-24 23:35:03.773 点餐系统[5649:707] 进入OrderListViewController.m的-(NSString *)documentsFolder
2013-01-24 23:35:03.780 点餐系统[5649:707] 进入OrderListViewController.m的-(void)animationOglFlip
2013-01-24 23:35:03.783 点餐系统[5649:707] 进入CommonAlert.m的dismissAlertView
2013-01-24 23:35:03.793 点餐系统[5649:690f] 进入JKCustomAlert.m的- (void) show
2013-01-24 23:35:03.805 点餐系统[5649:690f] 进入JKCustomAlert.m的- (void) layoutSubviews
2013-01-24 23:35:03.817 点餐系统[5649:690f] 进入JKCustomAlert.m的- (void) layoutSubviews
2013-01-24 23:35:03.824 点餐系统[5649:690f] 进入JKCustomAlert.m的- (void)drawRect:(CGRect)rect
解决方案: 在执行dismissAlertView前让线程暂停0.5秒,如: [NSThreadsleepForTimeInterval:0.5];