UITableView上编辑UITextView

来源:互联网 发布:博罗县政府网络问政 编辑:程序博客网 时间:2024/05/29 16:54

首先创建一个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];

    

}


0 0
原创粉丝点击