iOS:有没有一种方法可以按下一个按钮,同时按下另一个按钮?
我有一个“提交”按钮和一个在“编辑”和“取消”之间切换的按钮。当我按下“提交”按钮时,如何让“取消”按钮返回到“编辑”?如果我按“取消”,该按钮将切换回“编辑”。
这就是我所拥有的,但它不起作用。
- (IBAction)submitClicked:(id)sender {
[submitButton resignFirstResponder];
if (inEditMode)
[editButton setClicked:YES];
...
}
- (IBAction)editClicked:(id)sender {
if (inEditMode)
{
inEditMode = NO;
...
[sender setTitle:@"Edit" forState:UIControlStateNormal];
}
else
{
inEditMode = YES;
[sender setTitle:@"Cancel" forState:UIControlStateNormal];
}
[editButton resignFirstResponder];
}
谢谢,约翰
I have a "Submit" button and a button that toggles between "Edit" and "Cancel." How do I get the "Cancel" button to return to saying "Edit" when I press the "Submit" button? If I press "Cancel," that button will switch back to "Edit."
This is what I have, and it doesn't work.
- (IBAction)submitClicked:(id)sender {
[submitButton resignFirstResponder];
if (inEditMode)
[editButton setClicked:YES];
...
}
- (IBAction)editClicked:(id)sender {
if (inEditMode)
{
inEditMode = NO;
...
[sender setTitle:@"Edit" forState:UIControlStateNormal];
}
else
{
inEditMode = YES;
[sender setTitle:@"Cancel" forState:UIControlStateNormal];
}
[editButton resignFirstResponder];
}
Thanks, John
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要做的就是调用选择器
- (IBAction) editClicked:(id) sender
来单击提交按钮时模拟编辑按钮单击。单击提交的代码应如下所示:
请注意,您必须以某种方式传入编辑按钮,因此要小心一点,因为方法
editClicked
同时使用sender
和编辑按钮
。正如 @CodaFi 在评论中所说,您可能需要考虑始终使用相同的变量。What you want to do is call the selector
- (IBAction) editClicked:(id) sender
tosimulate an edit button click when the submit button is clicked. Your code for submit clicked should look like this:
Note that you have to pass in the edit button somehow, so be a little careful, because the method
editClicked
uses bothsender
andeditButton
. You might want to consider consistently using the same variable, as @CodaFi said in a comment.