2012年1月8日 星期日
2012年1月5日 星期四
運用thread實作背景load data,同時畫面show loading Image
1.一開始先看如何製作並管理thread在obj-c環境下---運用NSInvocationOperation
http://c.gzl.name/archives/tag/nsinvocationoperation
2.上面教學沒有教到call back main thread的方法,這裡有---performSelectorOnMainThread
http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation
3.有關畫面更新開發注意
除了main thread以外,其他thread不能使用UIkit,這意謂著你不能再其他thread做更新view的動作(addSubview: ....etc)
解決方法就是用第二點回到main thread並呼叫你想要的更新view的方法!
比如實作運用如MBProgressHUD來在main thread裡面做show Loading Image,然後在second thread裡面load data,load完之後再call back回main去執行[HUD removeFromSuperview];
4.如果配合MBProgressHUD開發而loading時間很長時(>5秒)請注意
另外有時候loading時間會很長,預設MBProgressHUD的loading image過一段時間(約5秒)不管是否有呼叫 removeFromSuperview都會自己消失,簡單得解決辦法是去MBProgressHUD.m找到hide方法,把它的
[self hideUsingAnimation:useAnimation];
這行註解調就可以了,這樣如果沒有呼叫removeFromSuperview圖案就不會消失囉~
http://c.gzl.name/archives/tag/nsinvocationoperation
2.上面教學沒有教到call back main thread的方法,這裡有---performSelectorOnMainThread
http://www.switchonthecode.com/tutorials/loading-images-asynchronously-on-iphone-using-nsinvocationoperation
3.有關畫面更新開發注意
除了main thread以外,其他thread不能使用UIkit,這意謂著你不能再其他thread做更新view的動作(addSubview: ....etc)
解決方法就是用第二點回到main thread並呼叫你想要的更新view的方法!
比如實作運用如MBProgressHUD來在main thread裡面做show Loading Image,然後在second thread裡面load data,load完之後再call back回main去執行[HUD removeFromSuperview];
4.如果配合MBProgressHUD開發而loading時間很長時(>5秒)請注意
另外有時候loading時間會很長,預設MBProgressHUD的loading image過一段時間(約5秒)不管是否有呼叫 removeFromSuperview都會自己消失,簡單得解決辦法是去MBProgressHUD.m找到hide方法,把它的
[self hideUsingAnimation:useAnimation];
這行註解調就可以了,這樣如果沒有呼叫removeFromSuperview圖案就不會消失囉~
2012年1月4日 星期三
AleartView---無網路提醒
這功能很重要
沒有apple會把你給退件!
1.先下載.h .m檔,這是ARC compatible版本
https://github.com/tonymillion/Reachability
2.使用no-wifi aleart教學
http://paulpeelen.com/2011/11/30/ios-4-ios-5-tutorial-uialertview-with-link-to-wifi-or-settings-app-using-reachability-and-xcode-4-2/
3.注意教學文是就算有3g沒wi-fi也提醒喔,所以改成
- (void)checkForHOSTConnection {
Reachability *hostReach = [Reachability reachabilityWithHostname:@"www.google.com"];
NSString *netStatus = [hostReach currentReachabilityString];
//NSLog(@"currentReachabilityString = %@", netStatus);
if ([netStatus isEqualToString:@"No Connection"])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"已關閉\"行動數據\"", @"AlertView")message:NSLocalizedString(@"開啟行動數據或使用WI-FI來取用資料。", @"AlertView")delegate:self cancelButtonTitle:NSLocalizedString(@"好", @"AlertView")otherButtonTitles:NSLocalizedString(@"設定", @"AlertView"), nil];
[alertView show];
}
}
會比較適當
沒有apple會把你給退件!
1.先下載.h .m檔,這是ARC compatible版本
https://github.com/tonymillion/Reachability
2.使用no-wifi aleart教學
http://paulpeelen.com/2011/11/30/ios-4-ios-5-tutorial-uialertview-with-link-to-wifi-or-settings-app-using-reachability-and-xcode-4-2/
3.注意教學文是就算有3g沒wi-fi也提醒喔,所以改成
- (void)checkForHOSTConnection {
Reachability *hostReach = [Reachability reachabilityWithHostname:@"www.google.com"];
NSString *netStatus = [hostReach currentReachabilityString];
//NSLog(@"currentReachabilityString = %@", netStatus);
if ([netStatus isEqualToString:@"No Connection"])
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"已關閉\"行動數據\"", @"AlertView")message:NSLocalizedString(@"開啟行動數據或使用WI-FI來取用資料。", @"AlertView")delegate:self cancelButtonTitle:NSLocalizedString(@"好", @"AlertView")otherButtonTitles:NSLocalizedString(@"設定", @"AlertView"), nil];
[alertView show];
}
}
會比較適當
2012年1月3日 星期二
畫面預載的Loading...畫面
https://github.com/jk/MBProgressHUD
參照上面project可以自由叫出loading畫面
但無法讓tableview先"預先載入空白畫面" 好讓我們在上面做loading
要再研究...
參照上面project可以自由叫出loading畫面
但無法讓tableview先"預先載入空白畫面" 好讓我們在上面做loading
要再研究...
pull & Pull-refresh depend on ARC
http://blog.csdn.net/w59879213/article/details/7165236
照著改,有些沒講到下面補充
註解掉.m下的- (void)dealloc {}方法
去build phases的link binary with ....加入quartzcore.framework
可以在arc下跑了
實作方法照舊~
照著改,有些沒講到下面補充
註解掉.m下的- (void)dealloc {}方法
去build phases的link binary with ....加入quartzcore.framework
可以在arc下跑了
實作方法照舊~
訂閱:
文章 (Atom)