返回到 iPhone 上使用 Core Data 的基于钻取导航的应用程序中的列表
我想构建一个简单的深入应用程序(类似于 iPhone 上的联系人应用程序)。我正在使用 Xcode 4.0。
我首先制作一个新的“基于导航的应用程序”,并且还说我将使用核心数据进行存储。然后我去添加“新文件”并选择 UIViewController 和 UIViewController 的子类。
在我的 RootViewControler (在模板中制作)的 didSelectRowAtIndexPath 中,我执行以下操作:
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
TrackerDetailViewController *trackerView = [[TrackerDetailViewController alloc] initWithNibName:@"TrackerDetailViewController" bundle:nil];
trackerView.title = [managedObject valueForKey:@"trackerName"];
trackerView.referringObject = managedObject;
[self.navigationController pushViewController:trackerView animated:YES];
[trackerView release];
这有效 - 我可以在 TrackerDetailViewController 中加载一些详细信息。
我似乎不知道如何回去!我在网上阅读的大多数地方都说这应该自动发生。我似乎无法让这种情况发生。如果我下载一些示例并编译它们,它们确实有一个后退按钮 - 但我不知道它是如何添加或管理的,也找不到我缺少的东西。
I want to build a simple drill down app (similar to the Contacts app on the iPhone). I am using Xcode 4.0.
I start by making a new "Navigation Based Application", and also say that I will be using Core Data for storage. I then go and add 'New File' and select UIViewController, and a subclass of UIViewController.
In my RootViewControler (which was made in the template) at didSelectRowAtIndexPath, I do the following:
NSManagedObject *managedObject = [self.fetchedResultsController objectAtIndexPath:indexPath];
TrackerDetailViewController *trackerView = [[TrackerDetailViewController alloc] initWithNibName:@"TrackerDetailViewController" bundle:nil];
trackerView.title = [managedObject valueForKey:@"trackerName"];
trackerView.referringObject = managedObject;
[self.navigationController pushViewController:trackerView animated:YES];
[trackerView release];
And this works - I can load up some details in TrackerDetailViewController.
What I cant seem to figure out is how to go back! Most places I am reading online say that this should be happening automatically. I can't seem to get that to happen. If I download a few samples and compile them, they do have a back button - but I dont see how it was added or managed, and can't find what I am missing to not have it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查
[managementObject valueForKey:@"trackerName"]
是否实际返回任何内容。如果不是,则没有标题,也不会创建后退按钮。哎呀,只需重新阅读您的代码即可。需要分配头衔的是父母。添加类似
self.title = @"myName;
的内容,然后 myName 应在 trackerView 中显示为后退按钮。Check if
[managedObject valueForKey:@"trackerName"]
is actually returning anything. If not, then there's no title, and no back button will be created.Oops, just re-read your code. It's the parent that needs a title assigned. Add something like
self.title = @"myName;
and myName should then appear as your back button in trackerView.