iphone - 将后退按钮添加到 View Controller
<p><p>我已经为我的 3 个 <code>UIToolBar</code> 项目创建了 3 个 <code>UIViewControllers</code>,但我无法在每个 Controller 上创建一个按钮,让我回到主页或主视图 Controller 。请帮助我,因为我是 objective-c的新手。</p>
<p>这是我的代码.... </p>
<p><strong>“ViewController.h”</strong></p>
<pre><code>#import "ViewController.h"
#import "ContactInfoViewController.h"
#import "DateViewController.h"
#import "MessageViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
;
UIToolbar *toolbar = [ init];
toolbar.frame = CGRectMake(0, 417, self.view.frame.size.width, 44);
UIBarButtonItem *contact = [ initWithTitle:@"Contact" style:UIBarButtonItemStyleDone target:self action:@selector(ContactButton)];
UIBarButtonItem *flexiableItem1 = [ initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *date = [ initWithTitle:@"Date" style:UIBarButtonItemStyleDone target:self action:@selector(DateButton)];
UIBarButtonItem *flexiableItem = [ initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *message = [ initWithTitle:@"Message" style:UIBarButtonItemStyleDone target:self action:@selector(MessageButton)];
NSMutableArray *items = [ initWithObjects:contact,flexiableItem1,date,flexiableItem,message, nil];
;
;
;
;
}
-(void)ContactButton
{
ContactInfoViewController *secondViewcont = [ init];
UINavigationController *navigCont = [ initWithRootViewController:secondViewcont];
;
}
-(void)DateButton
{
DateViewController *secondViewcont = [ init];
UINavigationController *navigCont = [ initWithRootViewController:secondViewcont];
;
}
-(void)MessageButton
{
MessageViewController *secondViewcont = [ init];
UINavigationController *navigCont = [initWithRootViewController:secondViewcont];
;
}
- (void)didReceiveMemoryWarning
{
;
}
@end
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>将自定义按钮添加到您的第二个 ViewController </p>
<p>在 <code>viewDidLoad</code> 你可以这样做</p>
<pre><code>self.navigationItem.rightBarButtonItem = [[initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)]autorelease];
- (IBAction)doneButtonPressed:(id)sender
{
;
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 将后退按钮添加到 ViewController ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/14722117/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/14722117/
</a>
</p>
页:
[1]