我已经写了一个代码来放置一个右栏按钮项目与customview。当选择编辑时,它会更改为保存选项。现在我选择保存,它保存了这些值。如果我再次尝试选择编辑动作不发射。我在下面写的代码
item = [[UINavigationItem alloc]init];
btnn = [UIButton buttonWithType:UIButtonTypeCustom];
[btnn setFrame:CGRectMake(0, 0, 40, 40)];
btnn.layer.masksToBounds = NO;
btnn.layer.cornerRadius = 8.0;
[btnn addTarget:self action:@selector(rightBarButtonCustomPressed:) forControlEvents:UIControlEventTouchUpInside];
[btnn setImage:[UIImage imageNamed:@"edit"] forState:UIControlStateNormal];
UIBarButtonItem* rightBtn = [[UIBarButtonItem alloc] initWithCustomView:btnn];
item.rightBarButtonItem = rightBtn;
self.navigationBar.items = @[item];
() - IBAction rightBarButtonCustomPressed:(UIBarButtonItem *) btn{
item = [[UINavigationItem alloc]init];
btnn = [UIButton buttonWithType:UIButtonTypeSystem];
[btnn setFrame:CGRectMake(0, 0, 40, 40)];
btnn.layer.masksToBounds = NO;
btnn.layer.cornerRadius = 8.0;
[btnn addTarget:self action:@selector(saveBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
[btnn setTitle:@"save" forState:UIControlStateNormal];
UIBarButtonItem* rightBtn = [[UIBarButtonItem alloc] initWithCustomView:btnn];
item.rightBarButtonItem = rightBtn;
self.navigationBar.items = @[item];
[self.firstNameText setEnabled:YES];
[self.lastNameText setEnabled:YES];
[self.dateOfBirthTxt setEnabled:YES];
[self.contactNumberlbl setEnabled:YES];
}
() - IBAction saveBtnClicked:(UIBarButtonItem *) btn {
[self.firstNameText setEnabled:NO];
[self.lastNameText setEnabled:NO];
[self.dateOfBirthTxt setEnabled:NO];
[self.contactNumberlbl setEnabled:NO];
item = [[UINavigationItem alloc]init];
btnn = [UIButton buttonWithType:UIButtonTypeCustom];
[btnn setFrame:CGRectMake(0, 0, 40, 40)];
btnn.layer.masksToBounds = NO;
btnn.layer.cornerRadius = 8.0;
[btnn addTarget:self action:@selector(rightBarButtonCustomPressed:) forControlEvents:UIControlEventTouchUpInside];
[btnn setImage:[UIImage imageNamed:@"edit"] forState:UIControlStateNormal];
UIBarButtonItem* rightBtn = [[UIBarButtonItem alloc] initWithCustomView:btnn];
item.rightBarButtonItem = rightBtn;
self.navigationBar.items = @[item];
我需要实现barbuttonitem作为切换保存和编辑选项。请任何人帮我解决这个问题。由于
在每次alloc init的地方,你为什么不尝试改变buttonTitle,然后你可以在它的基础上执行操作