简体   繁体   English

iPhone中的UITextView

[英]UITextView in iphone

i am creating textview(editable) through coding in uitableview in cellforrowatindexpath delegate. 我通过在cellforrowatindexpath委托中的uitableview中进行编码来创建textview(editable)。 textview is showing in every row correctly. textview正确显示在每一行中。 the problem is that when i am enter text in textview and scroll the tableview, then text disappear from textview. 问题是,当我在textview中输入文本并滚动tableview时,文本将从textview中消失。 if anyone has any idea? 如果有人有什么想法?

Make sure you are adding a different textview to each of the different reusable cells. 确保为每个不同的可重用单元格添加一个不同的textview。 If you have, say, 6 cells visible at any time, then you need 6 different textviews. 例如,如果您随时有6个单元格可见,则需要6个不同的textview。

It sounds like when you scroll, your textview gets used for another cell. 听起来像当您滚动时,您的textview被用于另一个单元格。

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    MyTableCell *cell = (MyListTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {      
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];

        cell.textView = [[[UITextView alloc] initWithFrame:/** put appropriate rect here **/] autorelease];
        // create other cell structures you need
    }


    // Set up the cell...
}

When you go to edit the text in the textview, the text scrolls up so that the top of the textview is where the new text will appear when typed. 当您在文本视图中编辑文本时,文本将向上滚动,以便在文本视图的顶部是键入新文本时出现的位置。 Try swiping down on the textview to reveal the previous info. 尝试向下滑动文本视图以显示先前的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM