UINavigationController에서“뒤로”버튼을 숨기는 방법?
UINavigationController에서 '뒤로'버튼을 숨기는 방법을 알고 있습니까? 또한 다시 표시하는 방법이지만 숨기는 것과 매우 유사합니다.
이메일을 보는 동안 '편집'을 누르면 메일 응용 프로그램이 iPhone에서하는 것처럼.
방금 컨트롤러에서 이것을 사용하여 답을 찾았습니다.
[self.navigationItem setHidesBackButton:YES animated:YES];
그리고 그것을 복원하려면 :
[self.navigationItem setHidesBackButton:NO animated:YES];
-
[최신 정보]
스위프트 3.0 :
self.navigationItem.setHidesBackButton(true, animated:true)
이 코드를 추가
[self.navigationItem setHidesBackButton:YES];
뒤로 버튼을 제거하는 것 외에도 (이미 권장 된 방법 사용) 사용자가 iOS 7 이상에서 왼쪽에서 오른쪽으로 스 와이프 동작으로 이전 화면으로 '팝'할 수 있다는 것을 잊지 마십시오.
이를 비활성화하려면 (적절한 경우) 다음을 구현하십시오 (예 : viewDidLoad).
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
기존 답변을 명확하게 설명하기 위해 : hidesBackButton
속성이 정답이지만 많은 답변에서 self
언급하는 내용이 명확하지 않습니다 . 기본적으로 self.navigationItem.hidesBackButton = YES
뷰 컨트롤러에서 으로 푸시 (또는 푸시)하려고 설정해야 합니다 UINavigationController
.
다시 말해, UINavigationController
이름이이라고 myNavController
합니다. 나는 그것에 새로운 견해를 넣고 싶다. 그리고 내가 할 때 뒤로 버튼이 더 이상 표시되기를 원하지 않는다. 나는 다음과 같은 것을 할 수있다 :
UIViewController *newVC = [[UIViewController alloc] init];
//presumably would do some stuff here to set up the new view controller
newVC.navigationItem.hidesBackButton = YES;
[myNavController pushViewController:newVC animated:YES];
코드가 완료되면에 의해 제어되는보기 newVC
가 표시되고 뒤로 버튼이 표시되지 않아야합니다.
조건부로 뒤로 버튼을 숨기거나 표시하려면 다음 코드를 사용할 수 있습니다.
-(void)viewDidAppear:(BOOL)animated
{
if ([tempAry count]==0)
{
[self.navigationItem setHidesBackButton:YES animated:YES];
}
else
{
[self.navigationItem setHidesBackButton:NO animated:YES];
}
[super viewDidAppear:animated];
}
참고 : 경우에 따라 viewWillAppear 대신 viewDidAppear 메서드에 배치해야합니다. 다음 클래스의 배열을 이전 클래스로 업데이트 한 다음 위와 같이 다음 클래스의 조건을 확인할 때.
스위프트 iOS (다음과 같이 사용했습니다)
// hide back button
self.navigationItem.setHidesBackButton(true, animated: false)
// pgrm mark ----- ------
// hide the back button for this view controller
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
self.navigationItem.setHidesBackButton(editing, animated: animated)
}// end setEditing
어떤 이유로 sethidesbackbutton이 작동하지 않았습니다.
나는이 방법을 사용했다->
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 30)]] ;
간단하고 가벼운 간단한 문제에 대해서는 항상 Apple 설명서를 사용하십시오. :)
Swift 3.0의 구문은 다음과 같습니다.
self.navigationItem.setHidesBackButton(true, animated:true)
참고
내 경우에는 현재 답변에 거의 문제가 없었습니다.
- 내부 viewDidLoad / viewWillAppear 뒤로 아이콘 만 숨겨지고 "Back"문자열이 비활성화되었지만 여전히 표시됨
- inside viewDidAppear the back button disappeared...but I did not want the user to see it at all
So the solution that finally have worked for me is:
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self.navigationItem setHidesBackButton:YES animated:NO];
}
return self;
}
The solution suggest by Zoran Simic didn't work for me for some reason.
This code did work however:
MyController* controller = [[MyController alloc] init];
NSArray* array = [[[NSArray alloc] initWithObjects:controller, nil] autorelease];
[self.navigationController setViewControllers:array animated:NO];
[controller release];
Obviously you'd have to manipulate an NSArray to your taste to make it work for you. Hope that helps somebody :)
In my UIViewController subclass I have this method:
-(void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated: animated];
// hide back button in edit mode
[self.navigationItem setHidesBackButton:editing animated:YES];
}
This hides the back button and replaces it with an add button in Swift:
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
// This hides the back button while in editing mode, which makes room for an add item button
self.navigationItem.setHidesBackButton(editing, animated: animated)
if editing {
// This adds the add item button
let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addTapped))
// Use the animated setter for the left button so that add button fades in while the back button fades out
self.navigationItem.setLeftBarButton(addButton, animated: animated)
self.enableBackGesture(enabled: false)
} else {
// This removes the add item button
self.navigationItem.setLeftBarButton(nil, animated: animated)
self.enableBackGesture(enabled: true)
}
}
func enableBackGesture(enabled: Bool) {
// In addition to removing the back button and adding the add item button while in edit mode, the user can still exit to the previous screen with a left-to-right swipe gesture in iOS 7 and later. This code disables this action while in edit mode.
if let navigationController = self.navigationController {
if let interactivePopGestureRecognizer = navigationController.interactivePopGestureRecognizer {
interactivePopGestureRecognizer.isEnabled = enabled
}
}
}
Swift 3.
Generally, you should use Apple's per-ViewController API as described many times already on this page, but sometimes you need immediate control of the Back button.
The following code hides the Back button and ensures that tap collision detection doesn't occur in the hidden button region.
let emptyView = UIView(frame: .zero)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: emptyView)
This hides the back button
let backBtn = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.plain, target: navigationController, action: nil)
navigationItem.leftBarButtonItem = backBtn
참고URL : https://stackoverflow.com/questions/1453519/how-to-hide-the-back-button-in-uinavigationcontroller
'programing tip' 카테고리의 다른 글
Excel VBA에서 정수를 문자열로 어떻게 변환합니까? (0) | 2020.06.06 |
---|---|
주어진 문자열이 Windows에서 유효한 / 유효한 파일 이름인지 어떻게 확인합니까? (0) | 2020.06.05 |
GitHub 메시지의 의미 : 이메일 개인 정보 제한으로 인해 푸시 거부 (0) | 2020.06.05 |
Javascript에서 HtmlSpecialChars가 동일합니까? (0) | 2020.06.05 |
MySQL에서 마지막 행을 선택하십시오. (0) | 2020.06.05 |