【问题标题】:Undo and Redo Button title and actions with NSUndomanagerNSUndomanager 的撤消和重做按钮标题和操作
【发布时间】:2013-01-17 12:49:25
【问题描述】:

我正在创建一个 ios 应用程序,例如数独。在该应用程序中,我创建了撤消重做按钮。在数独中,每个网格值都是按钮标题。我想要的是,每当我单击撤消或重做按钮时,网格值就会根据操作而改变.我可以用它NSUndomanager吗?有任何示例代码..吗?给我解决方案

  if([value intValue] == 0)
            {
                CurrentTitle=[NSString stringWithFormat:@"%@", [[b titleLabel ]text]];
                    [self AllSweepFunctionAction];
                    [b setTitle:appendedString forState:0];


                if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                {
                    [[b titleLabel] setFont:[UIFont fontWithName:@"Kids" size:15]];
                }else
                {
                    [[b titleLabel] setFont:[UIFont fontWithName:@"Kids" size:7]];
                }
                [b setTitleColor:[UIColor darkGrayColor] forState:0];
                [ b titleLabel].lineBreakMode = NSLineBreakByCharWrapping;
                [b titleLabel].textAlignment = NSTextAlignmentCenter;
            }

【问题讨论】:

  • 显示一些代码。你做了什么方法?

标签: iphone ios ipad-2


【解决方案1】:

首先,ViewControllers 需要能够成为处理手势的第一响应者,所以在你的 ViewController 中编写这个方法

- (BOOL)canBecomeFirstResponder 
{
    return YES;
}

其次:当视图控制器出现在屏幕上时,它需要成为第一响应者, 这可以通过在-loadView-viewDidLoad 中调用[self becomeFirstResponder] 来完成

[self performSelector:@selector(becomeFirstResponder) withObject:nil afterDelay:0.3];

你可以试试延迟时间

然后您可以在 viewController 中注册属性更改,并在您的按钮操作中调用 NSUndoManagerundo 方法。 另外我认为您可以覆盖此视图的控制器方法以进行编辑

- (void)setEditing:(BOOL)editing animated:(BOOL)animated {

    [super setEditing:editing animated:animated];
//do some editing 


}

这里是示例代码,包含撤消代码

这里是a link

在上面的代码链接中,将此代码添加到RootViewController.m的viewDidLoad中

 // left undo button
    UIBarButtonItem *undoButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(undoOperations:)];
    self.navigationItem.leftBarButtonItem = undoButton;

在这个RootViewController.m的某处添加这个方法

-(void)undoOperations:(id)sender
{
    [self.undoManager undo];

}

你应该有一个带撤消的左键,我认为这是一个好的开始。

【讨论】:

  • 请注意 link-only answers 是不鼓励的,所以答案应该是寻找解决方案的终点(与另一个中途停留的参考相比,随着时间的推移往往会变得陈旧)。请考虑在此处添加独立的概要,并保留链接作为参考。
  • 谢谢你的提示,我不知道))
猜你喜欢
  • 2011-03-29
  • 2023-03-25
  • 2012-06-22
  • 2011-07-02
  • 2011-05-31
  • 1970-01-01
  • 2021-05-23
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多