将多个 UITextView 设置为可编辑会导致光标在它们之间闪烁
当用户点击 UITableView 的“编辑”按钮时,我尝试将一组 UITableViewCell 中的 UITextView 设置为可编辑。每个 UITableViewCell 都有一个 UITextField (cell.blurb)。此代码会将每个 UITextView 设置为可编辑,但是,光标在每个 UITextView 之间快速交替。我很确定这是一个响应者链问题,(也许他们都成为了第一响应者?)但是我似乎无法补救。我尝试让每个 UITextView resignFirstResponder (除了列表中的第一个),但它什么也没做。在表格单元格 xib 中,它们是不可编辑的。
//set all text areas to editable and opaque
int numSections = [_tableView numberOfSections];
for (int s = 0; s < numSections; s++) {
int numRows = [_tableView numberOfRowsInSection: s];
for (int r = 0; r < numRows; r++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:r inSection:s];
CustomTableViewCell *cell = (CustomTableViewCell *)[_tableView cellForRowAtIndexPath:indexPath];
[cell blurb].editable = YES;
[[cell blurb] resignFirstResponder];
//set the first row's UITableView to the first responder
if (s == 0 && r == 0)
[[cell blurb] becomeFirstResponder];
}
}
I'm attempting to set the UITextViews in a set of UITableViewCell's to editable when the user taps the "edit" button for the UITableView. Each UITableViewCell has a UITextField (cell.blurb). This code will set each UITextView to editable, however, the cursor alternates very rapidly between each one. I'm pretty sure it's a responder chain issue, (they're all becoming first responders maybe?) however I can't seem to remedy it. I've tried having each UITextView resignFirstResponder (save for the first one in the list), but it does nothing. In the table cell xib they're uneditable.
//set all text areas to editable and opaque
int numSections = [_tableView numberOfSections];
for (int s = 0; s < numSections; s++) {
int numRows = [_tableView numberOfRowsInSection: s];
for (int r = 0; r < numRows; r++) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:r inSection:s];
CustomTableViewCell *cell = (CustomTableViewCell *)[_tableView cellForRowAtIndexPath:indexPath];
[cell blurb].editable = YES;
[[cell blurb] resignFirstResponder];
//set the first row's UITableView to the first responder
if (s == 0 && r == 0)
[[cell blurb] becomeFirstResponder];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我设法解决的唯一解决方案是创建两个 UITextView,一个可编辑,一个不具有相同的框架和属性,并根据可编辑状态管理每个 UITextView 的不透明度。很蹩脚不是吗?
另一件事,我必须在我的委托(恰好是 UITableViewCell 子类)中实现这一点:
否则,由于未知原因,UITableView 动画的结束(当它退出编辑模式时)再次触发其中一个 UITextView 上的变为FirstResponder。
这是 devforums 上的一个帖子 https://devforums.apple.com/message/290194
The only solution I managed to make work is create two UITextViews, one editable, one not with the same frame and properties, and manage opacity of each according to editable state. Quite lame isn't it ?
Another thing, I had to implement this in my delegate (which happens to be the UITableViewCell subclass):
otherwise, for an unknown reason, the end of the UITableView animation (when it quits editing mode) triggers again becomeFirstResponder on one of the UITextView.
Here is a thread on devforums https://devforums.apple.com/message/290194