iPhone應(yīng)用開發(fā)之學(xué)習(xí)點(diǎn)滴
iPhone應(yīng)用開發(fā)中學(xué)習(xí)點(diǎn)滴是本文要介紹的內(nèi)容,主要介紹了IPhone之NSBundle的使用、IPhone之ASINetworkQueue 異步隊(duì)列、IPhone之獲取Settings設(shè)置的內(nèi)容,來看本文內(nèi)容詳解。
IPhone之NSBundle的使用
NSBundle的對象可以獲取應(yīng)用程序安裝目錄的附件。
附件包括了,當(dāng)前應(yīng)用程序下,所有的文件。(圖片、屬性列表等)
獲取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 異步隊(duì)列
使用NSOperationQueue(或ASINetWorkQueue,見下面示例)將給你對異步request更多的控制。當(dāng)使用隊(duì)列的時(shí)候,只有確定數(shù)量的request可以同時(shí)運(yùn)行。如果你添加的request超過了隊(duì)列的maxConcurrentOperationCount屬性,request將在其他request運(yùn)行完了之后運(yùn)行。
注: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設(shè)置
IPhone中,可以用NSUserDefaults類讀取用戶設(shè)置。NSUserDefaults在尖用程序中只有一個(gè)實(shí)例在運(yùn)行。獲取代碼如下:
Key的值為 Root.plist中的Key值
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- [defaults objectForKey:@"username"];
- [defaults objectForKey:@"password"];
- [defaults objectForKey:@"protocol"];
- [defaults objectForKey:@"warp"];
- [[defaults objectForKey:@"warpFactor"] stringValue];
小結(jié):iPhone應(yīng)用開發(fā)之學(xué)習(xí)點(diǎn)滴的內(nèi)容介紹完了,通過本文介紹的IPhone之NSBundle的使用、IPhone之ASINetworkQueue 異步隊(duì)列、IPhone之獲取Settings設(shè)置的內(nèi)容,希望在你學(xué)習(xí)中能幫助到你。

















