2012-03-20 2 views
0

내 iPhone 응용 프로그램에서 IBAction을 수행 한 후 특정 ViewController (보기 닫기)를 표시하고 싶습니다. 시도했습니다.동작을 수행 한 후 특정 ViewController보기 또는 닫기

[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES]; 

그러나 작업이 수행 된 후에는 아무 것도 수행하지 않습니다.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; 
    if (selectedCell.tag == 1) 
    { 

     UIActionSheet *actionSheet = [[UIActionSheet alloc] 
             initWithTitle:@"Are you sure you want to delete this project?" 
     delegate:self cancelButtonTitle:@"No" destructiveButtonTitle:@"Yes, I’m Sure" otherButtonTitles:nil]; 
     [actionSheet showInView:self.view]; 


    } 

} 

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex != [actionSheet cancelButtonIndex]) 
    { 

     [self.tableView beginUpdates]; // Avoid NSInternalInconsistencyException 

     // Delete the project object that was swiped 
     Project *projectToDelete = self.project; 
     NSLog(@"Deleting (%@)", projectToDelete.name); 
     [self.managedObjectContext deleteObject:projectToDelete]; 
     [self.managedObjectContext save:nil]; 

    } 
} 

나는 사용자가 actionsheet에서 예 버튼을 누를 때 현재보기가 사라 할 :

는 더 많은 정보를 비트.

+0

가정 자체는 [자기 dismissModal ...]를 사용하지 않는 이유는 현재 표시되고있는 UIViewController를 말합니다 :

내가해야 할 일은이 방법을 사용했다. 문서에 따르면 호출은 자동으로 현재의보기 컨트롤러로 전달됩니다. 그러나 거기에 특이한 뷰 계층 구조가 없으면 프리젠 테이션 뷰 컨트롤러는 일반적으로 self.parentViewController가되며 self.parentViewController.parentViewController는 아닙니다. –

답변

1

내 탐색 스택의 첫 번째 (또는 루트) 뷰로 이동해야했습니다.

[controller.navigationController popToRootViewControllerAnimated:YES]; 
1
// Assume we are inside a UIViewController (or a subclass) 

DestinationController *destinationController = [[DestinationController alloc] init]; 
[self presentModalViewController:destinationController animated:YES]; 

... 

// Assume we are now in destination controller 

// Dismiss 
[self dismissModalViewControllerAnimated:YES]; 
+0

'NSInvalidArgumentException'이 발생했습니다. 이유는 다음과 같습니다. 'NSFetchedResultsController의 인스턴스에는 this가 아닌 fetchRequest 및 managedObjectContext가 필요합니다.'오류가 발생했습니다. – jcrowson

+0

@LordSnoutimus 좋습니다. 다른 이야기입니다. 즉, NSFetchedResultsController를 사용하여 coredata (UITableViewController의 데이터 소스로 사용됨)를 사용하여 관리 객체를 가져 오지만 가져 오기 요청과 컨텍스트를 제공하지 않았 음을 의미합니다. [더 자세히보기] (http://developer.apple.com/library/ios/#documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html) – Alladinian

0

보기 컨트롤러를 표시하거나 해제하는 또 다른 방법은 pushViewController 및 popViewController입니다.

의 ViewController가 보여 :

- (공극)과 pushViewController (UIViewController에 *)의 ViewController 애니메이션 (BOOL)는 애니메이션; // 가로 슬라이드 전환을 사용합니다. 뷰 컨트롤러가 이미 스택에 있으면 아무 효과가 없습니다.

그리고 기각 :

- (UIViewController에 *) popViewControllerAnimated (BOOL) 애니메이션; // 팝 된 컨트롤러를 반환합니다.

+0

이 방법은 정확하지만, 'UINavigationController' – Alladinian

관련 문제