2015-09-10 50 views
0
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 

    let cell = tableView.dequeueReusableCellWithIdentifier("SearchTableViewCellIdentifier") as! SearchTableViewCell 
    var item = self.searchResult[indexPath.row] as? PFObject 

    cell.post = item 


    return cell 
} 

FUNC的tableView(的tableView:UITableView的,didSelectRowAtIndex的rowIndex:智力) {獲取錯誤處理表中選擇行的iOS迅速

let indexPath = tableView.indexPathForSelectedRow() 

    let currentCell = tableView.cellForRowAtIndexPath(indexPath!)! as UITableViewCell 

    println(currentCell.textLabel!.text) 
} 

我沒有得到實際的價值。我上打印currentCell.textLabel獲得零!.text區段

回答

3

只是刪除override

class yourclassName: UIViewController, UITableViewDataSource, UITableViewDelegate 


var cod: AnyObject? 

override func viewDidLoad() { 
super.viewDidLoad() 

self.tableView.delegate = self 
self.tableView.dataSource = self 
} 

func tableView(tableView: UITableView, didSelectRowAtIndex rowIndex: Int) 
{ 

//Handle row selection 

    // choice 1 
    let indexPath = tableView.indexPathForSelectedRow(); 

    // if it is not work follow second option 
    cod = self.searchResult[indexPath.row] as? PFObject 

    // choice 2 
    cod = self.searchResult[rowIndex] as? PFObject 



    println(cod) 



    self.performSegueWithIdentifier("yourSegueName", sender: self) 
} 


    override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) { 
if (segue.identifier == "yourSegueName") { 
var svc = segue!.destinationViewController as secondViewController; 

svc.toPass = cod 

} 
} 

在你的第二個VC創建這個字符串

var toPass:String! 
+0

由於錯誤被刪除,但它無法正常工作。在選擇任何這種方法都沒有受到打擊。 – hatim

+0

@hatim - 檢查更新的答案 –

+0

它正在爲println打印nil(currentCell.textLabel!.text) – hatim