iPhone應用開發之學習點滴
iPhone應用開發中學習點滴是本文要介紹的內容,主要介紹了IPhone之NSBundle的使用、IPhone之ASINetworkQueue 異步隊列、IPhone之獲取Settings設置的內容,來看本文內容詳解。
IPhone之NSBundle的使用
NSBundle的對象可以獲取應用程序安裝目錄的附件。
附件包括了,當前應用程序下,所有的文件。(圖片、屬性列表等)
獲取XML文件
- NSString *filePath = [[NSBundle mainBundle] pathForResouse:@"re" ofType:@"xml"];
- NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];
獲取屬性列表
- NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]
- pathForResource:@"ViewControllers" ofType:@"plist"]];
IPhone之ASINetworkQueue 異步隊列
使用NSOperationQueue(或ASINetWorkQueue,見下面示例)將給你對異步request更多的控制。當使用隊列的時候,只有確定數量的request可以同時運行。如果你添加的request超過了隊列的maxConcurrentOperationCount屬性,request將在其他request運行完了之后運行。
注:ASINetworkQueue 類查看前面的IPhone之ASIHTTPRequest簡介
- //異步獲取圖片 ASINetworkQueue queue = [[ASINetworkQueue alloc] init];
- for (ForumItem *item in itemList)
- {
- //item.Image 圖片的地址
- if (item.Image)
- {
- ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURLURLWithString:item.Image]];
- request.userInfo = [NSDictionary dictionaryWithObject:item.ImageforKey:@"Image"];
- [request setDelegate:self];
- [request setDidFinishSelector:@selector(requestDidFinished:)];
- [queue addOperation:request];
- }
- }
- [queue go];
最后記的釋放:queue
IPhone之獲取Settings設置
IPhone中,可以用NSUserDefaults類讀取用戶設置。NSUserDefaults在尖用程序中只有一個實例在運行。獲取代碼如下:
Key的值為 Root.plist中的Key值
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- [defaults objectForKey:@"username"];
- [defaults objectForKey:@"password"];
- [defaults objectForKey:@"protocol"];
- [defaults objectForKey:@"warp"];
- [[defaults objectForKey:@"warpFactor"] stringValue];
小結:iPhone應用開發之學習點滴的內容介紹完了,通過本文介紹的IPhone之NSBundle的使用、IPhone之ASINetworkQueue 異步隊列、IPhone之獲取Settings設置的內容,希望在你學習中能幫助到你。