向iPad UISplitViewControl添加下一步按钮

向iPad UISplitViewControl添加下一步按钮,ipad,uisplitviewcontroller,next,rootview,Ipad,Uisplitviewcontroller,Next,Rootview,简单的问题(没错!)。我想在我的iPad项目的UISplitViewController的详细信息页面上添加一个“下一步”按钮。如果单击,这将是进入页面列表中下一页的另一种方式。作为奖励,我想突出显示根视图中与新视图相对应的正确行 任何关于去哪里的一般性指导和建议都会很棒 更新:感谢下面Anna的建议,下面是我用来整合所有这些的代码。它工作得很好。谢谢你,安娜 在详细信息页面上,我包括以下内容: - (IBAction)goToNext{ NSLog(@"Going to Next fr

简单的问题(没错!)。我想在我的iPad项目的UISplitViewController的详细信息页面上添加一个“下一步”按钮。如果单击,这将是进入页面列表中下一页的另一种方式。作为奖励,我想突出显示根视图中与新视图相对应的正确行

任何关于去哪里的一般性指导和建议都会很棒

更新:感谢下面Anna的建议,下面是我用来整合所有这些的代码。它工作得很好。谢谢你,安娜

在详细信息页面上,我包括以下内容:

- (IBAction)goToNext{
    NSLog(@"Going to Next from Welcome");
    [[NSNotificationCenter defaultCenter]
     postNotificationName:@"NextPageRequested" object:nil];

}
在RootViewController页面上,我执行了以下操作:

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter]
     addObserver:self selector:@selector(moveOnToNextPage:)
     name:@"NextPageRequested" object:nil];
}
最后,在RootViewController中:

#pragma mark -
#pragma mark The NEXT Button
// This is the Code used for the Big NEXT button.  basically a Notification Center listener is set up in the view did load and when triggered by any of the buttons, this 
// function is called.  Here, I do 3 things:  1.  advance the highlighted cell of the master table view.  2.  call the didSelectRowAtIndexPath function of the table to 
// advance to the next page.  and 3.  Exchange the "dash" icon with the "check" icon.


-(void)moveOnToNextPage:(NSNotification*)notifications {
    NSIndexPath*    selection = [self.tableView indexPathForSelectedRow]; // grab the row path of the currently highlighted item



// Change the icon in the current row:

    NSString *checkImage = [[NSBundle mainBundle] pathForResource:@"checkGreen" ofType:@"png"];
    UIImage *checkMark = [[[UIImage alloc] initWithContentsOfFile:checkImage] autorelease]; // Grab the checkmark image.
    if (selection) {
        NSLog(@"not nil");
        UITableViewCell *cell1 = [self.tableView cellForRowAtIndexPath:[self.tableView indexPathForSelectedRow]];
        // cell1.accessoryType = UITableViewCellAccessoryCheckmark; // this is yet another way to add the checkmar, but for now, I will use Mine.
        cell1.imageView.image = checkMark; // now set the icon
    } else {
        NSLog(@"must be nil");
        NSUInteger indexArrBlank[] = {0,0}; // now throw this back into the integer set
        NSIndexPath *blankSet = [NSIndexPath indexPathWithIndexes:indexArrBlank length:2]; // create a new index path 
        UITableViewCell *cell0 = [self.tableView cellForRowAtIndexPath:blankSet];
        // cell1.accessoryType = UITableViewCellAccessoryCheckmark; // this is yet another way to add the checkmar, but for now, I will use Mine.
        cell0.imageView.image = checkMark; // now set the icon
    }



// Highlight the new Row
    int nextSelection = selection.row +1; // grab the int value of the row (cuz it actually has both the section and the row {section, row}) and add 1
    NSUInteger indexArr[] = {0,nextSelection}; // now throw this back into the integer set
    NSIndexPath *indexSet = [NSIndexPath indexPathWithIndexes:indexArr length:2]; // create a new index path 
    [self.tableView selectRowAtIndexPath:indexSet animated:YES scrollPosition:UITableViewScrollPositionTop]; // tell the table to highlight the new row

// Move to the new View
    UITableView *newTableView = self.tableView; // create a pointer to a new table View
    [self tableView:newTableView didSelectRowAtIndexPath:indexSet]; // call the didSelectRowAtIndexPath function
    //[newTableView autorelease];  //let the new tableView go.  ok.  this crashes it, so no releasing for now.

}

实现这一点的一种方法是使用
NSNotificationCenter

viewDidLoad中的根视图控制器将调用
addObserver:selector:name:object:
,使自己成为名为@“NextPageRequested”的通知的观察者

点击详细视图上的按钮时,将调用
postNotificationName:object:
,以请求根视图控制器转到下一页

在根视图控制器中,通知处理程序方法将(假设根视图控制器是UITableView):

  • 使用UITableView的indexPathForSelectedRow获取当前索引路径
  • 计算下一个索引路径
  • 调用
    selectRowAtIndexPath:animated:scrollPosition:
    高亮显示该行
  • 调用实际更改页面所需的代码(可能直接调用
    tableView:didselectrowatinexpath:

为detailviewcontroller提供一个父导航控制器,并通过导航项将“下一步”按钮添加到导航栏。按下下一步将触发导航堆栈的pushviewcontroller


或者在当前视图控制器上添加一个顶部工具栏,然后将按钮放在那里。

Anna,我想这正是我要寻找的方向。我会尝试听从你的建议,看看会发生什么。@AnnaKerenina你太棒了。我的应用程序现在运行得很好!Nit:
viewDidLoad
可以为单个VC调用多次,例如,如果卸载视图然后重新加载。因此,在
initWith…
dealloc
中的
addObserver:…
removeObserver:self
中,必须小心何时/何地添加观察员:…I通常
addObserver:…
;否则,在多次
viewDidLoad
s之后,您可能会收到多个呼叫(例如,到下一页)。这类事情也需要调试!