ios - 在 Tableview 中,如何在 Objective C 中获取所选行的 textview 值
问题描述
如何获取所选行的 textview 值,我在 google 中对此进行了搜索,但没有得到正确的解决方案。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
arr = [[NSArray alloc]initWithObjects:@"Apple",@"ms-dynamicsxrm://?etn=thk_store&pagetype=entityrecord&id=7b74df21-e5a0-e711-810a-5065f38a9b71",@"Micromax",@"Nokia", nil];
}
#pragma mark - Table View Data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section {
return arr.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"cell_id";
SecondTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellIdentifier];
cell.label1.text = @"label";
NSString *txtDetailStr = [arr objectAtIndex:indexPath.row];
if ([txtDetailStr containsString:@"ms-dynamicsxrm://"]) {
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:txtDetailStr attributes:@{ NSLinkAttributeName: [NSURL URLWithString:txtDetailStr] }];
cell.textview1.attributedText = attributedString;
}
else {
cell.textview1.text = txtDetailStr;
}
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
如何获取所选行的 textview 值,我在 google 中对此进行了搜索,但没有得到正确的解决方案。
解决方案
您可以像这样获取所选行的 textview 值didSelectRowAtIndexPath
。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SecondTableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSLog(cell.textview1.text);
// If you want to get selected row data from your array then you can access it like this.
NSString *txtDetailStr = [arr objectAtIndex:indexPath.row];
NSLog(txtDetailStr);
}
推荐阅读
- python - 如何在加载大型库时加速 Pytest 启动(太慢)
- angular - Angular - 测试/模拟使用 rxjs fromEvent 的订阅
- c++ - 复制构造函数在复制 std::vector 时工作得更快
比 std::copy - ios - 有没有办法下载 USDZ 并将其放置在现实套件场景中?
- javascript - SonarQube - 使用 sonar-project.properties 覆盖质量配置文件
- flutter - 颤振:预期类型错误的值。传入字符串,小部件期待别的东西
- elasticsearch - elasticsearch 通过减去两个数字字段进行排序
- objective-c - 在 Objective-c 中使用 Earlgrey 的 IOS Programmatic Tap
- firebase - 使用 Firebase 消息打开应用时 Flutter 显示通知
- javascript - Cookies 在 HTTP 页面之间工作,而不是在 HTTPS 页面之间工作