Tag: undo

如何撤消一个行中的ios

我开发一个着色应用程序,但是我不能设法实现一个UNDObutton。 我不确定的方法,我尝试过实施NSUndoManager,但我无法得到有效的工作。 我的方法可能不正确。 林将不胜感激基于我的例子使用代码的答案。 – (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = NO; UITouch *touch = [touches anyObject]; lastPoint = [touch locationInView:self.view]; } – (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; UIGraphicsBeginImageContext(self.view.frame.size); [self.tempImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; //get the current touch point and then […]

“:范围{0,10}越界; string长度9“与撤消错误

当我尝试在UISearchBar撤消时,我的应用程序崩溃。 在我的应用程序,我有代码,以防止在search栏上input“%”符号,为此,它将textDidChange方法中的%replace为@“”,如下所示: – (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { self.searchBar.text = [searchText stringByReplacingOccurrencesOfString:@"%" withString:@""]; } 所以,如果我input文字“abc%xyz”,search栏上显示的最终文字就是“abcxyz”。 不,当我点击撤消,我看到'xyz'被清除,我仍然在search栏上看到'abc',而不是一次清除'abcxyz'。 现在,如果我再次点击撤消清除'abc'我的应用程序崩溃与[NSBigMutableString substringWithRange:]: Range out of bounds错误。 我假设即使'%'被replace为@“”,撤销pipe理器可能仍然持有它,因此范围超出了界限。 我试过[searchBar.undoManager removeAllActions]; 在用@“replace%后的textDidChange ,但是没有帮助。 这里是代码: – (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText { self.searchBar.text = [searchText stringByReplacingOccurrencesOfString:@"%" withString:@""]; [searchBar.undoManager removeAllActions]; } 问题:以前有人遇到类似的问题吗? 我如何处理撤消?