0
我使用tableView,裏面有UIImage,UILabel和FloatRatingView。 FloatRatingView是一個UIView,星級評分,你可以評分1-5。 所以tableView有多個單元格,當我按FloatRatingView時我想獲得電影標題。Swift:從選定的UIView獲取tableView indextPath/textLabel
FloatRatingView有兩個委託方法。
func floatRatingView(ratingView: FloatRatingView, didUpdate rating: Float) {
}
func floatRatingView(ratingView: FloatRatingView, isUpdating rating: Float) {
}
所以在我的自定義遠的TableCell我:
var delegate: FloatRatingViewDelegate?
@IBOutlet weak var userRating: FloatRatingView!{
didSet {
if userRating.rating>0 {
self.delegate!.floatRatingView(userRating, didUpdate: userRating.rating)
}}
}
,並在TableViewController:
class MoviesViewController: PFQueryTableViewController ,FloatRatingViewDelegate {
func floatRatingView(ratingView: FloatRatingView, isUpdating rating: Float) {
print("is updating")
}
func floatRatingView(ratingView: FloatRatingView, didUpdate rating: Float) {
print("did update")
}
和
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
let cellIdentifier:String = "cell"
var cell:TableCell? = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? TableCell
if(cell == nil) {
cell = TableCell(style: UITableViewCellStyle.Default, reuseIdentifier: cellIdentifier)
}
cell?.delegate = self
如何將回調轉發給單元委託? – PoolHallJunkie
我更新了我的代碼,但似乎我錯過了它背後的邏輯 – PoolHallJunkie