English 中文(简体)
• 如何把丁顿添加到美国航空测量局 手工操作?
原标题:How do i add a back button to a UINavigationBar manually?

I want a navigationbar to have a back button which goes to the last page, even though the last page didn t have a navigation bar. How can i insert a back button, and control what happens when the user presses it?

问题回答

我要补充一个答案,但不幸的是,我只是迅速得到正确的回答。 我将在此向在这一问题上寻求迅速答案的所有人提供。 请允许我向您的航道添加一个“Back Button”,以便进入最后一页。 如下:

    let button = UIBarButtonItem.init()
    button.title = "BACK"
    let attributes : [NSAttributedStringKey : Any] = [NSAttributedStringKey(rawValue: NSAttributedStringKey.font.rawValue): UIFont.systemFont(ofSize: 15.0)]
    button.setTitleTextAttributes(attributes, for: .normal)
    button.target = self
    button.action = #selector(self.goBack)
    self.navigationItem.setLeftBarButton(button, animated: false)

然后,界定一项功能(用于选择上述纽芬兰行动):

@objc func goBack() {
    self.performSegue(withIdentifier: "myUnwindSegue", sender: AnyObject.self) 
}

Note that here I make use of an unwind segue. To use an unwind segue, please refer to here or comment below if you have any questions. Unwind segues can be tricky when you first use them, but afterwards they are great. Also note that when you say "last page" I assume you mean a view already added to the view hierarchy.

你们需要把 but子从洲际建筑商连接到 when子被点击时你想要使用的方法。 这种方法应参照<代码>-(国际行动)反馈行动。 这种方法的名称由你来决定,但你必须宣布返回国际行动的类型,这样,Interface的建筑商知道,可以把一个纽州连接起来。

需由导航控制员管理的一个观察控制器使用一条航道。 不是试图绕开背.的纽子,而是利用导航控制器管理双眼控制器,并且有第一手控制器藏匿导航条。 例如,你可以补充:

[self.navigationController setNavigationBarHidden:YES animated:YES];

查阅控制器的方法。 第二名控制员的类似情况是,为了再次显示隐蔽参数,在诺特通过。

但是,一般情况下,一位观点控制者可以把ton子添加到像这种手法上(警告:从记忆中分类的未经测试的代码,但应当由你开始):

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:myBackImage style: UIBarButtonItemStylePlain target:self action:someAction];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];

When the button is tapped, the button will send its action (someAction) to its target (self).

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button addTarget:self action:@selector(back:) forControlEvents:UIControlEventTouchUpInside];

[button.titleLabel setFont:[UIFont boldSystemFontOfSize:11.0]];

[button setBackgroundImage:[UIImage imageNamed:@"back_norm.png"] forState:UIControlStateNormal];

[button setBackgroundImage:[UIImage imageNamed:@"back_click.png"] forState:UIControlStateSelected];

[button setBackgroundImage:[UIImage imageNamed:@"back_click.png"] forState:UIControlStateHighlighted];

[button setTitle:@" Back" forState:UIControlStateNormal];

[button setTitle:@" Back" forState:UIControlStateSelected];

[button setTitle:@" Back" forState:UIControlStateHighlighted];

button.frame = CGRectMake(0, 0, 48, 30);

UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithCustomView:button];

self.navigationItem.leftBarButtonItem = back; 

[button release];

[back release];




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...

热门标签