在父表视图的同级详细视图之间导航 [英] Navigate between sibling detail views of a parent table view
问题描述
我有一个表格视图,当我点击一个项目时,它会导航到详细信息视图.我想要做的是从详细视图导航到同级详细视图(对于表中的另一个项目),而不返回到父表视图.
例如,如果表格视图屏幕有许多属于这些类型的菜肴:
- 三明治
- 汤
- 沙拉
当我选择火腿三明治时,我会转到这道菜的详细信息视图.在这里我看到喜欢火腿三明治的人也喜欢鸡肉面条汤和凯撒沙拉.
我想从火腿三明治转到鸡肉面条汤或凯撒沙拉细节视图,而不用动画返回到表视图.我该怎么做?
当您想要导航到下一个/上一个详细信息视图(我们称之为兄弟详细信息视图)时,您只需弹出 &将动画标志设置为 FALSE 的新控制器推送
<预><代码>- (void)gotoAnotherDetailView{//删除当前[self.navigationController popViewControllerAnimated:FALSE];//创建一个新的DetailViewController* newcontroller = [DetailViewController alloc] initWithDishType:anotherDish];[self.navigationController pushViewController:newcontroller 动画:FALSE];}在这个例子中,DetailViewController 只是一个虚拟控制器,你应该用你在代码中实例化控制器的方式替换它.
正如我旁注的那样,Apple 建议使用委托模式来控制控制器的推送/弹出.这意味着控制器不会将自己从导航堆栈中弹出,而是会向父 tableview 控制器发送一条消息,并且该控制器将弹出并推送新的详细视图(在一次调用中).
I have a table view that navigates to a detail view when I tap on an item. What I am trying to do is navigate from a detail view to a sibling detail view (for another item in the table) without returning to the parent table view.
For example, if the table view screen has a number of dishes that belong to these types:
- Sandwiches
- Soups
- Salads
When I pick a ham sandwich I go to the detail view for this dish. Here I see that people who like ham sandwiches also like chicken noodle soup and Caesar salads.
I want to go from the ham sandwich to either the chicken noodle soup or Caesar salad detail views without animating back to the table view. How can I do this?
When you want to navigate to the next/prev detail view (let's call them sibling detail views), all you need to do it just pop & push the new controller with animated flag set to FALSE
- (void)gotoAnotherDetailView
{
// Just remove the current
[self.navigationController popViewControllerAnimated:FALSE];
// Create a new
DetailViewController* newcontroller = [DetailViewController alloc] initWithDishType:anotherDish];
[self.navigationController pushViewController:newcontroller animated:FALSE];
}
In this example, DetailViewController is just a dummy controller and you should replace this with however you instantiate controllers in your code.
As I side note, Apple recommends using the delegate pattern for controlling the pushing/poping of controllers. This mean that a controller will not pop itself out of the navigation stack, but will send a message to the parent tableview controller, and that controller will pop&push the new detail view (in one call).
这篇关于在父表视图的同级详细视图之间导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!