Tim*_*wen 6 iphone cocoa-touch uiviewcontroller uinavigationcontroller
我完全难过,这是情况:
我的应用程序使用Core Location框架获取用户的当前位置,然后将我的服务器ping TrailBehind用于附近有趣的地方并将其显示为列表.没问题.
为了节省电池,我从服务器获取数据后关闭了GPS服务.如果用户在使用应用程序时四处移动并想要一个新列表,则单击导航控制器上的"刷新"并再次激活CLLocation服务,将从服务器检索新的一批数据并重新绘制该表.
当应用程序从我的服务器抓取数据时,我加载了一个带有旋转地球仪的加载屏幕,上面写着"正在加载,请等待",我隐藏了导航栏,因此它们不会"返回".
因此,从服务器获取的初始数据可以完美无缺.
我第一次点击刷新所有代码执行以获取新位置,再次ping服务器以获取新的数据列表并更新单元格.但是,它应该恢复表视图的导航控制器栏,而不是加载表视图,但仍然在主窗口中显示我的加载视图.这只适用于设备,一切都在模拟器中完全正常.
第二次我点击刷新功能正常工作.
我点击刷新的第三次失败如上所述.
我点击刷新的第四次正常工作.
我点击刷新它的第五次失败如上所述.
等等,甚至刷新成功,奇怪的刷新失败.我逐行遍历所有代码,一切似乎正常执行.我其实继续加强对核心指令,庞大的单击"跳过之后"我发现表视图实际上在屏幕上某点CFRunLoopRunSpecific显示,但我然后单击"继续"和我加载视图接手屏幕.
我非常困惑.请帮忙!!非常感谢您的见解.
相关守则:
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];
}
}
Run Code Online (Sandbox Code Playgroud)
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];
}
}
Run Code Online (Sandbox Code Playgroud)
您可以尝试调试您的应用程序以查看调用 updateCells 时控件的位置吗?该应用程序似乎没有任何明显的问题。
确保在 LoadingViewController 类中没有内存警告。如果出现内存警告并且您的 RootViewController 的视图正在被释放,那么当您弹出到 RootViewController 时,viewDidLoad 将被再次调用。
在 viewDidLoad 和 updateCells 中保留断点。您确定没有在其他地方调用 LoadingViewController 吗?
| 归档时间: |
|
| 查看次数: |
7555 次 |
| 最近记录: |