2011-04-27 63 views
0

簡單的問題(是啊,對!)。我想在我的iPad項目的UISplitViewController的詳細信息頁面上添加一個「NEXT」按鈕。如果點擊,這將是另一種前進到頁面列表中下一頁的方式。作爲獎勵,我想突出顯示與您登陸的新視圖相對應的根視圖中的正確行。添加一個下一個按鈕到iPad UISplitViewControl

任何關於去哪兒的一般指導和建議都會非常棒!

更新:感謝下面的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. 

} 

回答

0

一個辦法執行這個是使用NSNotificationCenter

viewDidLoad中的根視圖控制器將調用addObserver:selector:name:object:使其自己成爲名爲@「NextPageRequested」的通知的觀察者。

點擊時詳細視圖上的按鈕將調用postNotificationName:object:來請求根視圖控制器轉到下一頁。

在根視圖控制器,所述通知處理程序的方法將(假設根視圖控制器被一個UITableView):

  • 使用的UITableView的indexPathForSelectedRow
  • 計算下一個索引路徑獲取當前索引路徑
  • 呼叫selectRowAtIndexPath:animated:scrollPosition:以突出該行
  • 電話需要真正改變頁面的代碼(可能通過直接調用tableView:didSelectRowAtIndexPath:
+0

安娜,我認爲這是我正在尋找的方向。我會嘗試遵循你的建議,看看會發生什麼。 – 2011-04-27 04:03:22

+0

@AnnaKerenina你真棒。我的應用程序正在運行完美! – 2011-04-27 21:04:20

+0

太好了,謝謝。 – Anna 2011-04-27 21:13:33

0

給你的detailviewcontroller一個父導航控制器,並通過導航項添加你的下一個按鈕到導航欄。按下Next會觸發一個pushviewcontroller到nav-stack。或者在您當前的視圖控制器中添加一個頂部工具欄,並將按鈕放在那裏。

相關問題