您的位置:首页 > 产品设计 > UI/UE

UITableView上编辑UITextView

2015-11-23 12:22 519 查看
首先创建一个currentTextView来表示当前编辑的是哪一个UItextView。

在beginEdit代理方法中,来确定currentTextView是具体哪儿UItextView.

然后在下面方法中算出当前的内容的高度,如果高度变化了,那么就让这个TextView的高度也变同时cell高度也变,同时刷新这个cell。

- (void)textViewDidChange:(UITextView *)textView{

// YLLog(@"textView.text is ------>%@",textView.text);

NSString *content = textView.text;
NSIndexPath *index = nil;

//20
是左右距离屏幕 10
是UITextView的文字距离View的大小
float wei = APP_SCREEN_WIDTH - 20 - 10;

CGSize size = [content boundingRectWithSize:CGSizeMake(wei,20000.0f)options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont
systemFontOfSize:14]}context:nil].size;

if (textView == self.informationTextView) {
self.currentTextView = self.informationTextView;
index = [NSIndexPath indexPathForRow:4 inSection:0];

if (size.height != self.informationSize.height) {
self.textIndex = 4;
self.informationSize = size;
[self reloadIndex:index];
}

}else if (textView == self.experienceTextView){
self.currentTextView = self.experienceTextView;
index = [NSIndexPath indexPathForRow:5 inSection:0];

if (size.height != self.experienceSize.height) {
self.textIndex = 5;
self.experienceSize = size;
[self reloadIndex:index];

}

}else if (textView == self.majorTextView){
self.currentTextView = self.majorTextView;
index = [NSIndexPath indexPathForRow:6 inSection:0];

if (size.height != self.majorSize.height) {
self.textIndex = 6;
self.majorSize = size;
[self reloadIndex:index];

}

}else if(textView == self.achievementTextView){

self.currentTextView = self.achievementTextView;
index = [NSIndexPath indexPathForRow:7 inSection:0];

if (size.height != self.achievementSize.height) {
self.textIndex= 7;
self.currentTextView = self.achievementTextView;
self.achievementSize = size;
[self reloadIndex:index];

}

}

[self autoScolToEdit:index];

}

- (void)autoScolToEdit:(NSIndexPath *)idnexPath{

[self.tbView scrollToRowAtIndexPath:idnexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

}
- (void)reloadIndex:(NSIndexPath *)indexPath{

[self.tbView reloadRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationNone];
[self updateViewConstraints];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: