2011-04-27 5 views
0

간단한 질문 (예!). 내 iPad 프로젝트의 UISplitViewController 세부 정보 페이지에 "NEXT"버튼을 추가하고 싶습니다. 클릭하면 페이지 목록의 다음 페이지로 넘어갈 수 있습니다. 보너스로, 당신이 착륙하는 새로운 뷰에 해당하는 루트 뷰에서 올바른 행을 강조하고 싶습니다.iPad에 NEXT 버튼 추가하기 UISplitViewControl

어디서 가야하는지에 대한 일반적인 지침과 제안은 아주 좋습니다.

업데이트 : 아래의 Anna 's Suggestion 덕분에, 여기이 모든 것을 함께 사용하기위한 코드가 있습니다. 잘됐다. 고마워요 애나.

- (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:을 호출하여 루트보기 컨트롤러에 다음 페이지로 이동하도록 요청합니다. 루트 뷰 컨트롤러에서

알림 처리기 방법은 (jQuery과 루트 뷰 컨트롤러를 가정 할) 것 :

  • jQuery과의 indexPathForSelectedRow
  • 다음 인덱스 경로를 계산하여 현재 인덱스 경로를 얻을
  • 실제로 해당 페이지를 변경하는 데 필요한 코드를 호출하십시오 (가능하면 tableView:didSelectRowAtIndexPath:을 직접 호출하여 호출)
  • 해당 행을 강조 표시하려면 selectRowAtIndexPath:animated:scrollPosition:으로 전화하십시오.
+0

안나, 이것이 정확히 내가 찾고있는 방향이라고 생각합니다. 나는 당신의 조언을 따르고 무슨 일이 일어나는지를 보려고 시도 할 것입니다. –

+0

@AnnaKerenina 당신은 최고입니다. 내 응용 프로그램이 완벽하게 실행 중입니다! –

+0

위대한, 고마워. – Anna

0

세부 viewcontroller에 상위 navigationcontroller를 지정하고 네비게이션 항목을 통해 다음 버튼을 navbar에 추가하십시오. 다음을 누르면 pushviewcontroller가 nav-stack으로 트리거됩니다.

또는 현재보기 컨트롤러에 상단 툴바를 추가하고 버튼을 배치하십시오.

관련 문제