导航详细信息栏中的向上/向下箭头可浏览父表中的对象 [英] Up/down arrows in nav bar of detail view to page through objects in parent table

查看:61
本文介绍了导航详细信息栏中的向上/向下箭头可浏览父表中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在详细信息视图的导航栏右侧创建了一个向上/向下箭头分段的控制按钮.在基于表的应用程序中,如何使用这些向上/向下箭头在父表中的单元格之间移动?

I have created an up/down arrow segmented control button on the right side of the navigation bar in my detail view. In a table based application, how can I use these up/down arrows to move through cells in the parent table?

苹果的"NavBar"示例代码中有一个示例,但是控件不起作用.

The apple "NavBar" sample code has an example of this but the controls are not functional.

iBird程序也具有此功能,非常好.免费下载"iBird 15"程序.

The iBird program has this functionality as well and it is very nice. Download the "iBird 15" program for free.

有什么想法吗?

谢谢!

推荐答案

我已经解决了一些小问题.这是我当前的代码.它不是很优雅,但是可以正常工作. segmentActionPressed是.h文件中的NSInteger设置,我用于指定是否使用段控件移动到下一个视图.

I have got it working with a few small problems. Here is my current code. It's not very elegant but it's working. segmentActionPressed is an NSInteger set in the .h file which I use to specify if the segment control was used to move to the next view.

- (IBAction)segmentAction:(id)sender{
NSIndexPath *selectedRow = CurrentIndexPath; //CurrentIndexPath is an NSIndexPath object that holds the current indexpath.
NSIndexPath *scrollIndexPath;
self.segmentActionPressed = 1;
self.tableView.delegate = self;

if([sender selectedSegmentIndex] == 0)
{
[self.navigationController popViewControllerAnimated:NO];
    if(selectedRow.row == 0)    //If on the first row when up button is pressed, send us to the last row.
    {
        scrollIndexPath = [NSIndexPath indexPathForRow:tableDataSource.count -1 inSection:selectedRow.section];
        [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:tableDataSource.count -1 inSection:selectedRow.section] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
        [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:tableDataSource.count -1 inSection:selectedRow.section]];
    }
    if(selectedRow.row > 0)     //If on any other row when up button is pressed, go to the next row above.
    {
        scrollIndexPath = [NSIndexPath indexPathForRow:selectedRow.row -1 inSection:selectedRow.section];
        [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:scrollIndexPath.row inSection:selectedRow.section] animated:NO scrollPosition:UITableViewScrollPositionMiddle];
        [self tableView:self.tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:scrollIndexPath.row inSection:selectedRow.section]];
    }
}
else if([sender selectedSegmentIndex] == 1)
{
[self.navigationController popViewControllerAnimated:NO];
    if(selectedRow.row == tableDataSource.count -1)     //If on the last row when up down is pressed, go to the first row.
    {
        scrollIndexPath = [NSIndexPath indexPathForRow:0 inSection:selectedRow.section];
        [self.tableView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
        [self tableView:self.tableView didSelectRowAtIndexPath:scrollIndexPath];
    }
    if(selectedRow.row < tableDataSource.count -1)      //If on any other row when up down is pressed, go to the next row below.
    {
        scrollIndexPath = [NSIndexPath indexPathForRow:selectedRow.row +1 inSection:selectedRow.section];
        [self.tableView selectRowAtIndexPath:scrollIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
        [self tableView:self.tableView didSelectRowAtIndexPath:scrollIndexPath];
    }
}}

在我的-didSelectRowAtIndexPath方法中,如果使用向上/向下箭头,则使用以下代码移动到没有动画的下一个视图.

In my -didSelectRowAtIndexPath method, I used the following code to move to the next view without animation if the up/down arrows are used.

if (segmentActionPressed == 0)
    {
    [self.navigationController pushViewController:tvc animated:YES];
    }
else if (segmentActionPressed == 1)
    {
    [self.navigationController pushViewController:tvc animated:NO];
    }

最后,我设置以下代码以在出现父视图时将segmentActionPressed设置为"0".我还将在此处取消选择该行,以便您返回到父视图时可以看到选择了哪一行.

Finally, I set the following code to set the segmentActionPressed to "0" when the parent view appears. I also deselect the row here so you can see which row was selected when you move back to the parent view.

- (void)viewWillAppear:(BOOL)animated {
self.segmentActionPressed = 0;
[self.tableView deselectRowAtIndexPath:CurrentIndexPath animated:YES];}

主要问题是分段按钮永远不会显示为按下状态,并且在触摸时立即发送该动作,而不是像在内部向上触摸"动作那样释放该按钮时.

The main problem is that the segment buttons never appear pressed and the action is sent immediately when touched instead of when the button is released as with the "touch up inside" action.

这篇关于导航详细信息栏中的向上/向下箭头可浏览父表中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆