我完全难倒,这里的情况:为什么popViewController只工作每个其他时间
我的应用程序使用核心定位框架来获取用户的当前位置,然后在TrailBehind坪我服务器有趣的地方附近并将它们显示为一个列表。没问题。
为了节约电池,我从服务器获取数据后关闭了GPS服务。如果用户在使用应用程序时四处移动并想要一个新列表,他会在导航控制器上单击“刷新”,然后再次激活CLLocation服务,从服务器检索新的一批数据并重新绘制表格。
当应用程序从我的服务器获取数据时,我加载了一个旋转地球仪的加载屏幕,其中显示“正在加载,请稍候”,我隐藏了导航栏,因此它们不会“回”。
因此,从服务器获取的初始数据完美无瑕。
第一次刷新所有代码执行以获取新位置时,再次ping服务器以获取新数据列表并更新单元格。但是,应该不是像加载表格视图一样,而是为表格视图恢复导航控制器栏,但仍然在主窗口中显示我的加载视图。这只在设备上才是真实的,在模拟器中一切正常。
第二次我点击刷新功能正常工作。
第三次我刷新它失败,如上所述。
第四次点击刷新它正常工作。
第五次我刷新它失败,如上所述。
等等,甚至刷新成功,奇怪的刷新失败。我一行一行地遍历所有的代码,一切似乎都正常执行。我实际上继续介绍了核心指令,经过大量点击“逐步”后,我发现表格视图实际上在CFRunLoopRunSpecific的某个点显示在屏幕上,但是我点击了“继续”,我的加载视图接管了屏幕。
我感到非常困惑。请帮忙!!非常感谢您的洞察力。
Video of the strange behavior:
相关代码:
RootViewControllerMethods(这是此的TableView项目的基本视图)
- (void)viewDidLoad {
//Start the Current Location controller as soon as the program starts. The Controller calls delegate methods
//that will update the list and refresh
[MyCLController sharedInstance].delegate = self;
[[MyCLController sharedInstance].locationManager startUpdatingLocation];
lv = [[LoadingViewController alloc] initWithNibName:@"Loading" bundle:nil];
[self.navigationController pushViewController:lv animated:YES];
[super viewDidLoad];
}
- (void)updateClicked {
//When the location is successfully updated the UpdateCells method will stop the CL manager from updating, so when we want to update the location
//all we have to do is start it up again. I hope.
[[MyCLController sharedInstance].locationManager startUpdatingLocation];
[self.navigationController pushViewController:lv animated:YES];
//LV is a class object which is of type UIViewController and contains my spinning globe/loading view.
}
-(void)updateCells {
//When the Core Location controller has updated its location it calls this metod. The method sends a request for a JSON dictionary
//to trailbehind and stores the response in the class variable jsonArray. reloadData is then called which causes the table to
//re-initialize the table with the new data in jsonArray and display it on the screen.
[[MyCLController sharedInstance].locationManager stopUpdatingLocation];
if(self.navigationController.visibleViewController != self) {
self.urlString = [NSString stringWithFormat:@"http://www.trailbehind.com/iphone/nodes/%@/%@/2/10",self.lat,self.lon];
NSURL *jsonURL = [NSURL URLWithString:self.urlString];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:jsonURL];
NSLog(@"JsonData = %@ \n", jsonURL);
self.jsonArray = [jsonData JSONValue];
[self.tableView reloadData];
[self.navigationController popToRootViewControllerAnimated:YES];
[jsonData release];
}
}
CLController方法:基本上只是所有数据发送直接回到RootViewController的
// Called when the location is updated
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
NSLog(@"New Location: %@ \n", newLocation);
NSLog(@"Old Location: %@ \n", oldLocation);
@synchronized(self) {
NSNumber *lat = [[[NSNumber alloc] init] autorelease];
NSNumber *lon = [[[NSNumber alloc] init] autorelease];
lat = [NSNumber numberWithFloat:newLocation.coordinate.latitude];
lon = [NSNumber numberWithFloat:newLocation.coordinate.longitude];
[self.delegate noteLat:lat];
[self.delegate noteLon:lon];
[self.delegate noteNewLocation:newLocation];
[self.delegate updateCells];
}
}
你有没有通过调试这些方法加强? 运行仪器以查看对象创建/删除是否符合您的期望? 对不起,如果我侮辱你的智力,但因为我没有看到问题的快速看,我要做的下一件事就是开始逐步... – mikeh 2009-05-04 03:28:44
如果你离开应用程序是否会出现弹出窗口?看起来你不会离开应用足够的时间来获得视频中的GPS修复。 尝试在locationManager方法中设置断点。 – 2009-05-04 07:40:44