iphone - 从 uitextview 中删除选定的文本

标签 iphone ios ios4

我有一个 TextView ,我需要能够删除选定的文本 [我的意思是我想删除突出显示的文本] 为此我做了如下操作

代码

(void)textViewDidChangeSelection:(UITextView *)textView {
    NSRange range = textView.selectedRange;
   myTextView.text = [myTextView.text stringByReplacingCharactersInRange:range withString:@""];

}

但是它崩溃了,如何在这里实现这个功能

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString replaceCharactersInRange:withString:]: Range or index out of bounds'

请告诉我

最佳答案

它在 xcode 版本 3.2.5 上运行良好。检查 UITextView 的委托(delegate)是否已连接到 Interface Builder 中的文件所有者。

-(void) textViewDidChangeSelection:(UITextView *)textView {     
NSRange range = textView.selectedRange;
myTextView.text = [myTextView.text stringByReplacingCharactersInRange:range withString:@""];
}

关于iphone - 从 uitextview 中删除选定的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8641613/

相关文章:

iphone - 为什么 revmob 广告闪烁?

iPhone OpenGL ES glFlush() 不一致地慢

iphone - 在 UIAlertView 的文本中显示可调用的电话号码

ios - 主页按钮可将应用程序最小化

iphone - 如何使 iPhone 应用程序兼容多个 SDK(固件)版本

iphone - 困惑 : SKSpriteNode & SKTexture difference.

iphone - 嵌入没有 uiwebview 的 youtube 视频?

ios - 如何使用 Firebase 存储点赞

ios - 'SwiftClass' 不可用 : cannot find Swift declaration for this class - iOS Simulator only

ios - 快速观察或跟踪每个功能的进度条