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];
}
在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];
}
相关文章推荐
- QT的QSqlQuery与QSqlQueryModel RowCount只能读到256问题的解决
- 设置UIButton 字体 颜色
- request.getQueryString();
- String、StringBuffer、StringBuilder区别,HashMap与HashTable区别,final关键字详解及初始化成员变量位置,static关键字详解,抽象类与接口区别
- Gradle build设置自动log开关
- iOS 官方文档 UIGestureRecognizer
- Extjs6 ComboBox之queruMode
- Cocoa 多线程编程之 block 与 dispatch quene(ios转载大神)
- stl_deque.h
- stl_queue.h
- UITextView 响应 键盘的return(完成键)
- HDU5568 sequence2(dp+大数)
- [leetcode] 51. N-Queens
- UITableView的删除、添加,dataPick的使用
- Kibana User Guide [4.2] » Visualize » Tile Maps
- arduino编译过程
- java后台jsp Request获取url信息的各种方法比较
- Android systemUI移植
- session.createQuery()与createSQLQuery()区别
- UIViewContentMode各类型效果