我是 iOS 开发的新手。我使用 Storyboard 创建了一个应用程序来导航到不同的页面。
当我单击客户页面中的添加栏按钮时-> 转到添加客户页面。(使用Modal
Storyboard Segue)
在那里,当我输入用户名和密码并单击保存按钮时->返回客户页面。
一切正常。
问题是我想back button
在添加客户页面中有。我已经知道我可以使用Push
Storyboard Segue,但是当我使用它时,我遇到了一个错误:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
*** First throw call stack:
(0x13cb022 0x155ccd6 0xeff1b 0xefa24 0x44bde6 0x4404d0 0x13cce99 0x1814e 0x256a0e 0x13cce99 0x1814e 0x180e6 0xbeade 0xbefa7 0xbe266 0x3d3c0 0x3d5e6 0x23dc4 0x17634 0x12b5ef5 0x139f195 0x1303ff2 0x13028da 0x1301d84 0x1301c9b 0x12b47d8 0x12b488a 0x15626 0x25ed 0x2555)
terminate called throwing an exception(lldb)
客户视图控制器.h:
#import "AddCustomerViewController.h"
@interface CustomerViewController : UITableViewController<AddCustomerViewControllerDelegate>
{
IBOutlet UITableView *tableview;
NSMutableArray *customers;
}
@property(nonatomic,retain)IBOutlet UITableView *tableview;
@property(nonatomic,retain)NSMutableArray *customers;
@end
这是我在 CustomerViewController.m 中使用的代码:
self.customers = [[NSMutableArray alloc]init];
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"AddCustomer"])
{
UINavigationController *navigationController = segue.destinationViewController;
AddCustomerViewController *addCustomerViewController = [[navigationController viewControllers] objectAtIndex:0];
addCustomerViewController.delegate = self;
}
}
-(void) addCustomerViewControllerDidSave: (AddCustomerViewController *) Controller newCustomer: (Customer *) customer
{
[self dismissViewControllerAnimated: YES completion:NULL];
[self.customers addObject:customer];
[self.tableview reloadData];
}
AddCustomerViewController.h:
#import "Customer.h"
@class AddCustomerViewController;
@protocol AddCustomerViewControllerDelegate <NSObject>
-(void) addCustomerViewControllerDidSave: (AddCustomerViewController *) Controller newCustomer: (Customer *) customer;
@end
@interface AddCustomerViewController : UITableViewController
{
}
@property (nonatomic, weak) id <AddCustomerViewControllerDelegate> delegate;
@property (nonatomic, strong) IBOutlet UITextField *firstnameTxt;
@property (nonatomic, strong) IBOutlet UITextField *lastnameTxt;
- (IBAction)save:(id)sender;
@end
和 AddCustomerViewController.m:
- (void)save:(id)sender
{
NSLog(@"Save");
Customer *newCustomer = [[Customer alloc]init];
newCustomer.firstname = self.firstnameTxt.text;
newCustomer.lastname = self.lastnameTxt.text;
[self.delegate addCustomerViewControllerDidSave:self newCustomer:newCustomer];
}
你能帮我如何使用Push
Storyboard Segue(有后退按钮)吗?