嘿傢伙我到目前爲止已經用ASIHTTPRequest做了很多工作,並在我的ios應用程序中多次使用它,但是在我的應用程序的一個區域中,我添加了另一個asihttprequest方法,它無法正常工作。ASIHTTPRequest在模擬器上工作,但不是iphone
都必須說,我想之所以傳播下載和分析數據..的負載如果我這樣做就需要一個很好的2-3秒要經過第二子視圖的第一XML表,並獲取所有相關的值出來..如果我在這個主視圖上做的人沒有看到任何負載等,然後當回到子視圖應該看起來幾乎是即時的。我不知道這是多麼正確,但我認爲它是一個好的事情,使應用程序感覺更好用。
所以我將它設置了asihttprequest方法同樣作爲工作負緩存其他的。
會發生什麼事是我選擇的是加載第二個視圖,並解析了一堆資料到的tableview的主視圖表格單元格。用戶然後選擇一個傳回主視圖並顯示的值。
我然後解析另一個大量的XML數據檢查選擇VALUEID針對在第二XML片的一切。這樣當用戶選擇第二個單元格時,我將剛剛解析的所有數據傳遞給第二個視圖,以使其看起來好像它的加載速度更快。
繼承人的一個流程圖將解釋什麼,我試圖做的更好升技
這是解析器代碼看起來像在這是一個多數民衆贊成在仿真器,但不工作的主視圖在iphone上。
這是我的方案,我從子視圖調用並傳遞我管得太多和斷火的請求mainviews ASIHTTPRequest的所有值。
- (void) setManufactureSearchFields:(NSArray *)arrayValues withIndexPath:(NSIndexPath *)myIndexPath
{
manufactureSearchObjectString = [[arrayValues valueForKey:@"MANUFACTURER"] objectAtIndex:0];
manufactureIdString = [[arrayValues valueForKey:@"MANUID"] objectAtIndex:0]; //Restricts Models dataset
manufactureResultIndexPath = myIndexPath;
[self.tableView reloadData]; //reloads the tabels so you can see the value in the tableViewCell.
//need some sort of if statment here so that if the back button is pressed modelSearchObjectString is not changed..
if (oldManufactureSearchObjectString != manufactureSearchObjectString) {
modelResultIndexPath = NULL;
modelSearchObjectString = @"empty";
oldManufactureSearchObjectString = [[NSString alloc] initWithFormat:manufactureSearchObjectString];
}
//These two lines below are what execute ASIHTTPRequest and set up my parser etc
dataSetToParse = @"ICMod"; // This sets the if statment inside parserDidEndDocument
[self setRequestString:@"ICMod.xml"]; //Sets the urlstring for XML inside setRequestString
}
然後觸發ASIHTTPRequest委託方法。
- (IBAction)setRequestString:(NSString *)string
{
//Set database address
//NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8888/codeData/"]; // imac development
NSMutableString *databaseURL = [[NSMutableString alloc] initWithString:@"http://127.0.0.1:8888/codeData/"]; // iphone development
//PHP file name is being set from the parent view
[databaseURL appendString:string];
NSLog(@"%@", databaseURL);
//call ASIHTTP delegates (Used to connect to database)
NSURL *url = [NSURL URLWithString:databaseURL];
//This sets up all other request
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
當我通過與斷點調試運行此同時,在iPhone上,這是在應用程序翻倒測試..但在模擬器上它沒有問題。
在iphone上測試時,這種下一個方法永遠不會被調用,但在模擬器上工作得很好。
- (void)requestFinished:(ASIHTTPRequest *)request
{
responseString = [request responseString]; //Pass requested text from server over to NSString
capturedResponseData = [responseString dataUsingEncoding:NSUTF8StringEncoding];
[self startTheParsingProcess:capturedResponseData];
}
這是在iphone上測試時唯一被觸發的其他代表,發給我一個表示連接超時的alret。
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
NSLog(@"%@", error);
UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"A connection failure occurred." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[errorAlert show];
}
我不認爲你需要看到所有的解析器的代表,因爲我不認爲他們是問題,因爲這是在應用程序倒下......
這裏是獲取打印到日誌...
2011-11-29 14:38:08.348 code[1641:707] http://000.000.000.000:0000/codeData/second.xml
2011-11-29 14:38:18.470 code[1641:707] Error Domain=ASIHTTPRequestErrorDomain Code=2 "The request timed out" UserInfo=0x1e83a0 {NSLocalizedDescription=The request timed out}
如果你需要更多的我的代碼讓我知道..但我在這裏損失的升技是像我說有就是林如何這樣做ASIHTTPRequest無差異除了我從我從第二個視圖設置的協議初始化它之外的其他視圖..也許我應該設置VA在我重新裝入桌子之前發生了一些事情......我不確定,但希望有人能幫助我解決這個問題,並發現我看不到的問題。
你在iPhone上運行Web服務器嗎?在你有不同的地址之前,你將其改爲http://127.0.0.1:8888。 – ThomasW