UITextView 中的控制选择
我不希望用户能够选择我的 UITextView
的前几个字符。我尝试对其进行子类化并注意到诸如 -setSelectedRange:
和 -setSelectedTextRange:
之类的方法。两者都在不同的时间被调用,但似乎我需要的是后者。
-setSelectedTextRange:
方法采用一个 UITextRange
对象,该对象具有一个名为“start”的 UITextPosition
属性。这听起来像是我想要的,但我无法写入它,并且该对象没有类。
有人对我如何做到这一点有任何想法吗? FWIW,我正在尝试复制 Facebook 在 iPhone 应用程序上的“签到”视图。
提前致谢!
I do not want the user to be able to select the first few characters of my UITextView
. I have tried subclassing it and noticed methods such as -setSelectedRange:
and -setSelectedTextRange:
. Both are called at different times but it seems like it's the latter that I need.
The -setSelectedTextRange:
method takes a UITextRange
object, which has a UITextPosition
property called "start". This sounds like what I want but I cannot write to it, and there are no classes for this object.
Does anyone have any ideas on how I can do this? FWIW, I'm trying to replicate what Facebook have on their "Check-In" view on their iPhone app.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我个人并不熟悉 Facebook 应用程序签入视图的功能,但根据您的描述,听起来您的子类中需要类似的东西:
特别是,请注意“offset:1”参数。您应该能够使用它来设置所选文本范围的开头。此外,您还需要确保指定的新文本范围对于文本字段中的字符数有效。
I'm not personally familiar with the functionality of the Facebook app Check-In view, but based on your description, it sounds like you need something like this in your subclass:
In particular, note the "offset:1" argument. You should be able to use this to set the start of your selected text range. Also, you'll want to make sure that the new text range you specify is valid for the number of characters that are in the text field.