uitableview – 如何获取swift中所选行的textLabel?

uitableview – 如何获取swift中所选行的textLabel?,第1张

概述所以我试图获取我选择的行的textLabel的值。我尝试打印它,但它没有工作。经过一番研究,我发现这段代码有效,但只有在Objective-C中; - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"did selec 所以我试图获取我选择的行的textLabel的值。我尝试打印它,但它没有工作。经过一番研究,我发现这段代码有效,但只有在Objective-C中;
- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath    *)indexPath    {        NSLog(@"dID select  and the text is %@",[tableVIEw cellForRowAtIndexPath:indexPath].textLabel.text);]    }

我找不到Swift的任何解决方案。打印indexpath.row是可能的,但这不是我需要的。

所以我该怎么做?或者这个代码的“Swift-version”是什么?

尝试这个:
overrIDe func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) {    let indexPath = tableVIEw.indexPathForSelectedRow() //optional,to get from any UIbutton for example    let currentCell = tableVIEw.cellForRowAtIndexPath(indexPath) as UItableVIEwCell    print(currentCell.textLabel!.text)
总结

以上是内存溢出为你收集整理的uitableview – 如何获取swift中所选行的textLabel?全部内容,希望文章能够帮你解决uitableview – 如何获取swift中所选行的textLabel?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1054697.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存