嘿家伙我到目前为止已经用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