gpt4 book ai didi

ios - 从 UITableView 中的 UITextView 更新 DataSource

转载 作者:行者123 更新时间:2023-11-29 10:59:01 25 4
gpt4 key购买 nike

我有一个 UITableView,每个 UITableViewCell 都包含一个可编辑的 UITextView

我的数据源是一个包含 NSMutableDictionaryNSMutableArray,它保存文本值和文本的一些样式键。

我怎样才能(有效地)使用户对 UITextView 所做的任何更改都更新到相应的数据源 NSMutableDictionary

最佳答案

一个相当简单的方法是利用表的索引路径,它不是最干净的,所以它取决于数据源的复杂性,以及是否有多个表等。

你可以做的是当用户结束编辑 textView 或在 tableView 中选择另一行时,你读取所选行的 indexPath (这要求该行在编辑 textView 时保持实际处于选中状态,它应该默认情况下)。从那里调用更新方法。

catch 你实现的编辑结束

-(void)textViewDidEndEditing:(UITextView *)textView
{
NSIndexPath *selectedpath = [myTable indexPathForSelectedRow];
[self myUpdateMethodForIndexPath:selectedpath];
}

要捕获表格行的取消选择并且上面的代码不会被调用,您需要实现

-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self myUpdateMethodForIndexPath:indexPath];
}

然后,您的更新方法必须在 indexPath 的相应单元格中读取 textView 的值,并在数据源中处理它。当然,要照顾部分,您需要正确处理 indexPath,在示例中只使用了行(1 个部分)。

-(void)myUpdateMethodForIndexPath:(NSIndexPath *)editPath 
{
UITableViewCell *editCell = [myTable cellForRowAtIndexPath:editPath];
NSString *newText = editCell.theTextView.text;
....
NSMutableDictionary *dict = [myDictArray objectAtIndex:editPath.row];
....
}

关于ios - 从 UITableView 中的 UITextView 更新 DataSource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16877946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com