2016-02-15 52 views
0

我想在自定義表中的按鈕中填充標籤。所有工作,除了我不知道如何將計算的數據從我的IBAction函數發回UITableView函數,因此它通過return cell語句顯示。將值返回給tableView函數

請參閱代碼和下面的代碼中的註釋:

import UIKit 

class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { 
    @IBOutlet weak 
    var lblHeader: UILabel! 
     @IBOutlet weak 
    var tableView: UITableView! 

     var players: NSMutableArray! = NSMutableArray() 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     self.players.addObject("Hannah") 
     self.players.addObject("Katie") 
     self.players.addObject("Ashley") 
     self.players.addObject("Kate") 
    } 

    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
      // Dispose of any resources that can be recreated. 
    } 

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) - > Int { 
     return self.players.count 
    } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) - > UITableViewCell { 
     let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as!CustomCell 


     cell.plrZeroes.tag = indexPath.row 
     cell.plrZeroes.addTarget(self, action: "plrOnesAction:", forControlEvents: .TouchUpInside) 
     return cell 
    } 

    @IBAction func plrOnesAction(sender: UIButton!) { 
     let pAvg = self.players.objectAtIndex(sender.tag) as ? String 

     ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * 
     HERE I WANT TO SEND 「pAvg」 BACK TO THE CALLER SO I CAN INCLUDE IT IN THE 「return cell」 LINE OF THE TABLEVIEW FUNCTION 
     ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** * 
    } 
} 
+1

只需再次填充數據源,並重新加載tableview。 – iAnurag

+0

謝謝,但這對我來說都是新的。我可以通過填寫數據源和重新加載表來獲得一個例子。什麼鱈魚呢? – CNE

+0

你打算如何使用pAvg? – iAnurag

回答

2

可以使用indexpath

讓電池= tableView.cellForRowAtIndexPath(NSIndexPath(forRow得到細胞:sender.tag,切入口:0))