2010-12-12 102 views

回答

1

您可以讓tableView控制器在創建tableview單元格時設置一個屬性,表明它是委託和數據源。

在您創建的tableviewcell類上添加一個屬性,該屬性是您tableview控制器的一個實例。像

@property (nonatomic, retain) MyTableViewController * pickerDelegate; 

然後在你的cellForRowAtIndexPath您可以在屬性設置爲自

cell.pickerDelegate = self; 

您可能還需要設置某種額外的屬性就像一個標籤中的每個細胞區別開來。我會認爲像NSIndexPath這樣的tableviewcell上的另一個屬性會做。

+0

非常感謝,現在就試一試... – 2010-12-12 20:46:03

+0

爲你做了這個工作嗎? – geekydevjoe 2011-01-13 23:26:16

0

對於斯威夫特:

class MyTableViewCell: UITableViewCell, UIPickerViewDelegate, UIPickerViewDataSource { 
    @IBOutlet var myPickerView: UIPickerView! 
} 
  • 在ViewController中添加委託和數據源中 「的cellForRowAtIndexPath」:

    class myViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITableViewDelegate, UITableViewDataSource { 
        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {    
         let cell = tableView.dequeueReusableCellWithIdentifier("myCell") as! MyTableViewCell 
    
         cell.myPickerView.dataSource = self 
         cell.myPickerView.delegate = self 
    
         return cell 
        } 
    } 
    
    1. 自定義表視圖類UIPickerView創建出口