Ios5 “如何链接故事板”;“保存”;按下保存按钮时,按钮将动作发送到代码,同时将视图返回到主视图?
我在使用故事板时遇到问题。没有故事板,我的代码如下:Ios5 “如何链接故事板”;“保存”;按下保存按钮时,按钮将动作发送到代码,同时将视图返回到主视图?,ios5,action,storyboard,Ios5,Action,Storyboard,我在使用故事板时遇到问题。没有故事板,我的代码如下: - (void)viewDidLoad { self.title = @"Add Login"; self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
- (void)viewDidLoad
{
self.title = @"Add Login";
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancel_Clicked:)] autorelease];
NSLog(@"hello");
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemSave
target:self action:@selector(save_Clicked:)] autorelease];
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
[super viewDidLoad];
}
此代码将帮助我使用导航栏上的2个按钮“取消”和“保存”设置视图
自从我开始使用情节提要以来,我自己在情节提要视图上创建了按钮,并将取消键链接回导航控制器,样式为模态。因此,当我单击“取消”时,它会正常工作,返回到上一个视图。但是我的“保存”按钮不起作用了,因为它没有指向任何东西。即使我添加了上面提到的代码并实现了相应的方法
还需要注意的是,在使用storyboard之后,上述代码即使我将它们全部删除,也不会影响我在storyboard中设计它的方式。所以我认为代码现在是多余的,对吗?因为即使我在代码中更改了标题,故事板中设置的标题也会显示出来
- (void) save_Clicked:(id)sender {
NSLog(@"Saved Clicked");
LoginDBAppDelegate *appDelegate = (LoginDBAppDelegate *)[[UIApplication sharedApplication] delegate];
//Create a Login Object.
Login *loginObj = [[Login alloc] initWithPrimaryKey:0];
loginObj.loginDesc = txtloginDesc.text;
loginObj.loginURL = txtloginURL.text;
loginObj.loginUserName = txtloginUserName.text;
loginObj.password = txtpassword.text;
/*NSString *URL = [[NSString alloc] initWithString:txtloginURL.text];
loginObj.loginURL = URL;
[URL release];
NSString *username = [[NSString alloc] initWithString:txtloginUserName.text];
loginObj.loginURL = username;
[username release];
NSString *password = [[NSString alloc] initWithString:txtpassword.text];
loginObj.loginURL = password;
[password release];
*/
loginObj.isDirty = NO;
loginObj.isDetailViewHydrated = YES;
//Add the object
[appDelegate addLogin:loginObj];
//Dismiss the controller.
[self.navigationController dismissModalViewControllerAnimated:YES];
}
我应该怎么做才能将我在故事板中制作的“保存”按钮链接到.m文件中单击的“保存”方法
更新:
通过将(void)更改为(IBAction),我成功地将save按钮链接到代码,因此我能够保存数据。但按“保存”后,视图仍保留
当我尝试连接save(保存)按钮时,按返回到storyboard中的导航控制器时,它会返回到主页面,但数据最终没有保存。当我取消链接并检查数据库时,数据可以保存,但视图仍然保持不变