iOS:有没有一种方法可以按下一个按钮,同时按下另一个按钮?

发布于 2024-12-24 18:39:49 字数 663 浏览 1 评论 0原文

我有一个“提交”按钮和一个在“编辑”和“取消”之间切换的按钮。当我按下“提交”按钮时,如何让“取消”按钮返回到“编辑”?如果我按“取消”,该按钮切换回“编辑”。

这就是我所拥有的,但它不起作用。

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟沫凡尘 2024-12-31 18:39:49

您要做的就是调用选择器 - (IBAction) editClicked:(id) sender
单击提交按钮时模拟编辑按钮单击。单击提交的代码应如下所示:

    - (IBAction)submitClicked:(id)sender {
        [submitButton resignFirstResponder];
        if (inEditMode)
            [self editClicked:editButton];
            ...
    }

请注意,您必须以某种方式传入编辑按钮,因此要小心一点,因为方法 editClicked 同时使用 sender编辑按钮。正如 @CodaFi 在评论中所说,您可能需要考虑始终使用相同的变量。

What you want to do is call the selector - (IBAction) editClicked:(id) sender to
simulate an edit button click when the submit button is clicked. Your code for submit clicked should look like this:

    - (IBAction)submitClicked:(id)sender {
        [submitButton resignFirstResponder];
        if (inEditMode)
            [self editClicked:editButton];
            ...
    }

Note that you have to pass in the edit button somehow, so be a little careful, because the method editClicked uses both sender and editButton. You might want to consider consistently using the same variable, as @CodaFi said in a comment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文