0

簡単な質問です(そうです!)。iPad プロジェクトの UISplitViewController の詳細ページに「次へ」ボタンを追加したいと考えています。クリックすると、ページのリストの次のページに進む別の方法になります。おまけとして、新しいビューに対応するルート ビューの正しい行を強調表示したいと思います。

どこに行くべきかについての一般的なガイダンスと提案は素晴らしいでしょう!

更新: 以下のアンナの提案のおかげで、これらすべてをまとめるために使用したコードを次に示します。それはうまくいきます。ありがとうアンナ。

詳細ページにこれを含めました:

- (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.

}
4

2 に答える 2

0

これを実装する 1 つの方法は、 を使用することNSNotificationCenterです。

ルート ビュー コントローラは、viewDidLoad でaddObserver:selector:name:object:、@"NextPageRequested" などの名前の通知のオブザーバになるように呼び出します。

詳細ビューのボタンをタップするとpostNotificationName:object:、ルート ビュー コントローラーに次のページに移動するように要求する呼び出しが行われます。

ルート ビュー コントローラーでは、通知ハンドラー メソッドは次のようになります (ルート ビュー コントローラーが UITableView であると仮定します)。

  • UITableView を使用して現在のインデックス パスを取得するindexPathForSelectedRow
  • 次のインデックス パスを計算する
  • selectRowAtIndexPath:animated:scrollPosition:その行を強調表示する呼び出し
  • 実際にページを変更するために必要なコードを呼び出します (おそらくtableView:didSelectRowAtIndexPath:直接呼び出すことによって)
于 2011-04-27T02:28:40.933 に答える
0

detailviewcontroller に親ナビゲーション コントローラーを与え、ナビゲーション アイテムを介してナビゲーション バーに次のボタンを追加します。[次へ] を押すと、pushviewcontroller が nav-stack にトリガーされます。

または、現在のビュー コントローラーにトップ ツールバーを追加し、そこにボタンを配置します。

于 2011-04-27T02:29:04.963 に答える