如何在自定义原型单元格文件中获取行号
How to get row number in custom Prototype Cell file
我已经为该单元创建了自定义原型单元和 "peopleTableViewCell.swift" 文件。
该单元格有一个删除按钮,单击删除后,我希望删除该行。
按钮的 IBAction 在 "peopleTableViewCell.swift" 文件中。
如何将行号从 "viewController.swift" 文件传递到 "peopleTableViewCell.swift"
请帮忙......
您可以使用此代码在 UITableViewCell 子类中获取 IndexPath。
Objective C
- (void)awakeFromNib
{
NSIndexPath *indexPath = [(UITableView *)self.superview.superview indexPathForCell: self];
NSLog(@"Row : %d", indexPath.row);
}
Swift
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
if let tableView : UITableView = self.superview.superview as! UITableView?{
let indexForCell : NSIndexPath = tableView.indexPathForCell(self)!
let row = indexForCell.row
print("Row : \(row)")
}
}
我已经为该单元创建了自定义原型单元和 "peopleTableViewCell.swift" 文件。 该单元格有一个删除按钮,单击删除后,我希望删除该行。
按钮的 IBAction 在 "peopleTableViewCell.swift" 文件中。
如何将行号从 "viewController.swift" 文件传递到 "peopleTableViewCell.swift"
请帮忙......
您可以使用此代码在 UITableViewCell 子类中获取 IndexPath。
Objective C
- (void)awakeFromNib
{
NSIndexPath *indexPath = [(UITableView *)self.superview.superview indexPathForCell: self];
NSLog(@"Row : %d", indexPath.row);
}
Swift
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
if let tableView : UITableView = self.superview.superview as! UITableView?{
let indexForCell : NSIndexPath = tableView.indexPathForCell(self)!
let row = indexForCell.row
print("Row : \(row)")
}
}