所以我试图获取我选择的行的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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。