0

UIBarButtonItem を押してアクションを実行しようとしています。その場合、BarButtonItem のタイトルの名前を変更しています。そうすれば、もう一度ヒットした場合、すべてをコード化して元に戻すのではなく、実行したアクションを元に戻したいと思います。これが私のコードの例です。

- (IBAction)MyAction:(id)sender{

if([[MyButton title] isEqualToString:@"Test1"]){

//My Action is performed.

    [MyButton  setTitle:@"Test2"];
    [[undoManager prepareWithInvocationTarget:self] MyAction:?];
    [undoManager setActionName:@"UndoLastAction"];


}else if ([[MyButton title] isEqualToString:@"Test2"]){

    [MyButton setTitle:@"Test1"];
    [[undoManager prepareWithInvocationTarget:self]MyAction:?];
    [undoManager setActionName:@"UndoLastAction"];
}

}
4

2 に答える 2

0

必要に応じて試してみてください。

viewDidLoad.,,. にプログラムで UIButton を追加します。

 - (void)viewDidLoad
{
MyButton =[UIButton buttonWithType:UIButtonTypeRoundedRect];
[MyButton setFrame:CGRectMake(300, 450, 72, 37)];
[MyButton setTitle:@"Test1" forState:UIControlStateNormal]; 
[MyButton addTarget:self action:@selector(MyAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view MyButton];

}

そして、このようなアクションを与えます,.,.,

 -(IBAction)MyAction:(id)sender
 { 
   UIButton *temp=(UIButton *)sender;

    if(temp.titleLabel.text==@"Test1")
    {
       [temp setTitle:@"Test2" forState:UIControlStateNormal]; 

    }
    else if (temp.titleLabel.text==@"Test2")
    {
      [temp setTitle:@"Test1" forState:UIControlStateNormal]; 
    }

}

私は学んでいます、。、..、

于 2012-04-30T04:55:10.247 に答える
0

元のコードを再実行してアクションを「元に戻す」方が簡単です。

于 2012-04-29T18:24:15.813 に答える