- (void)textViewDidChange:(UITextView *)textView
{
CGPoint pos = [textView convertPoint:CGPointZero toView:self.editTableView];
NSIndexPath *indexPath = [self.editTableView indexPathForRowAtPoint:pos];
NSLog(@"indexpath %@", indexPath);
AHAttribute *attribute = self.schedule.attributes[indexPath.row];
attribute.value = textView.text;
NSLog(@"changed Attribute textView %@", attribute.value);
}
你看,当我在TableView中的textView中插入7行时,该方法可以工作7次 然后,NSLog告诉我这个:
indexPath {length = 2, path = 4 - 0}
changed Attribute textView (newline)
indexPath {length = 2, path = 4 - 0}
changed Attribute textView (newline)
(newline)
indexPath {length = 2, path = 4 - 0}
changed Attribute textView (newline)
(newline)
(newline)
indexPath {length = 2, path = 4 - 0}
changed Attribute textView (newline)
(newline)
(newline)
(newline)
indexPath {length = 2, path = 4 - 0}
changed Attribute textView (newline)
(newline)
(newline)
(newline)
(newline)
indexPath {length = 2, path = 4 - 0}
changed Attribute textView (newline)
(newline)
(newline)
(newline)
(newline)
(newline)
indexPath {length = 2, path = 3 - 1}
-error code...-
所以我改变了我的代码:
- (void)textViewDidChange:(UITextView *)textView
{
UITableViewCell *cell = [[[textView superview] superview] superview];
NSIndexPath *indexPath = [self.editTableView indexPathForCell:cell];
NSLog(@"indexpath %@", indexPath);
AHAttribute *attribute = self.schedule.attributes[indexPath.row];
attribute.value = textView.text;
NSLog(@"changed Attribute textView %@", attribute.value);
}
然后更改代码显示我想要的一个indexPath。 但为什么第一个代码会显示另一个indexPath?如果你帮助我,我很感激。