簡體   English   中英

點擊UITableView的單元格,其他視圖不會出現

[英]Tap on cell of UITableView and the other view doesn't appear

我有一個tableView帶有一些搜索結果。 我已將第一個和第二個視圖與“ storyboard Segue”從單元格連接到第二個視圖。

這是在第一個ViewController中編寫的代碼:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {

    let indexPath = self.tableProva.indexPathForSelectedRow?.row

    let vc = segue.destination as! DettaglioNewViewController

    vc.titleLibro = posts[indexPath!].name
    vc.authorLibro = posts[indexPath!].author
    vc.ISBNLibro = posts[indexPath!].ISBN

}

在其他項目中,它工作正常,但在該項目中,它不起作用,以顯示我必須點擊並向右或向左滑動的第二個viewController。

看來問題出在圖形上。 如果我嘗試單擊該單元格,則不會變為灰色。 如果我長按它會變成灰色

這有發生在其他人身上嗎?

誰能幫我?

您應該使用'didSelectRowAtIndexPath'方法,以便針對特定單元格選擇不同的視圖。 采用.....

var storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle(forClass: self.dynamicType))

vc = storyboard.instantiateViewControllerWithIdentifier("LoginVC") as DettaglioNewViewController
vc.loadView()

.....搜集所需的信息。

*信息示例*

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
    myFavIndex = indexPath.row
    let storyBoard = UIStoryboard(name: "Main", bundle:nil)
    let view = storyBoard.instantiateViewControllerWithIdentifier("LoginVC") as! DettaglioNewViewController
    view.imageURL = self.imageArray[mySelectedIndex]
    view.titleString = self.titleArray[mySelectedIndex]
    self.presentViewController(view, animated: true, completion: nil)
}

在上面的示例中,我使用新的View Controllers圖像和標題作為view.imageURLview.titleString通過[mySelectedIndex]從我選擇的單元格信息中填充視圖元素。 您應該能夠使用IntUIImageString ,例如

您無需根據代碼初始化控制器。 只需創建一個自定義segue並在表委托的'didSelect'方法中調用'performSegue'方法即可。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
      self.performSegueWithIdentifier("yourIdentifierInStoryboardForCustomSegue", sender: nil)
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM