Programing

iOS에서 프로그래밍 방식으로 탐색 컨트롤러 뒤로 버튼 호출

lottogame 2020. 9. 17. 18:50
반응형

iOS에서 프로그래밍 방식으로 탐색 컨트롤러 뒤로 버튼 호출


UINavigationController 기반 iPhone 앱에서 메서드에서 뒤로 버튼을 눌렀다가 다시보기로 돌아가는 것과 같은 프로그래밍 방식을 수행하고 싶습니다.

즉, 여기에 표시된대로 작업 버튼을 자동으로 누릅니다.

내비게이션 컨트롤러 이미지

내가 걸 수있는 일반적인 iOS 전화가 있습니까? 아니면 추가 정보가 필요합니까?


UINavigationController-popViewControllerAnimated:메서드는 원하는 작업을 수행해야합니다.

[navigationController popViewControllerAnimated:YES];

실제로 버튼을 프로그래밍 방식으로 누르지 않고 단순히 버튼을 누른 결과를 복사하기를 원하지 않는다고 가정하면 내비게이션 컨트롤러에 현재 뷰 컨트롤러를 팝하도록 지시해야합니다.

[self.navigationController popViewControllerAnimated:YES];

그러면 스택에서 제거되고 이전 뷰 컨트롤러로 돌아갑니다.


스위프트 3.0

루트보기로 돌아 가기

self.navigationController?.popToRootViewController(animated: true)

이전보기로 돌아 가기

self.navigationController?.popViewController(animated: true)

스위프트 2.3

루트보기로 돌아 가기

self.navigationController?.popToRootViewControllerAnimated(true)

이전보기로 돌아 가기

self.navigationController?.popViewControllerAnimated(true)

당신은 전화해야합니다

popViewControllerAnimated:

뷰 컨트롤러를 추가하는 것과 반대입니다. pushViewController:animated:


[self.navigationController popViewControllerAnimates:YES];

가장 좋은 옵션이지만 동일한 뷰 컨트롤러 클래스에 있지 않거나 뒤로 버튼 메서드가 호출되기 전에 델리게이트가 변경되면 시도 할 수도 있습니다.

먼저 뒤로 버튼을 정의해야합니다.

UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"anyTitleForBackButton" style: UIBarButtonItemStyleBordered target: nil action: @selector(backButtonTapped)];

[[self navigationItem] setBackBarButtonItem: newBackButton];

[newBackButton release];

그런 다음 backButtonTapped 메서드에서 호출 할 수 있습니다.

[self.navigationController pushViewController:desiredViewController animated:YES];

참고 URL : https://stackoverflow.com/questions/2107876/programmatically-call-navigation-controller-back-button-on-ios

반응형