2016-11-11 43 views
0

我的tableView:didSelectRowAtIndexPath的实施不起作用。
另一方面,滑动执行。
我想单击表格行时显示另一个页面。tableView:didSelectRowAtIndexPath失败

这是我的代码:

func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) { 


    let tableCell: SearchTableViewCell = tableView.dequeueReusableCell(withIdentifier: "searchcell") as! SearchTableViewCell 


    if(self.searchstatus == "people") 
    { 
     if(useridarray.object(at: (indexPath as NSIndexPath).row) as! NSString != "null") 
     { 

      self.searchdelegate.otheruserid=useridarray.object(at: (indexPath as NSIndexPath).row) as! NSString; 
      let ProfilePageViewController = self.storyboard?.instantiateViewController(withIdentifier: "otherprofile") 
      self.present(ProfilePageViewController!, animated: false, completion: nil) 
     } 
    } 
    else 
    { 
     if(useridarray.object(at: (indexPath as NSIndexPath).row) as! NSString != "null") 
     { 
      let hashtag1=search.text!.replacingOccurrences(of: "#", with: "") 
      self.searchdelegate.hashtag="\(hashtag1)" as NSString! 
      self.searchdelegate.hashtag=searchdelegate.hashtag.trimmingCharacters(in: CharacterSet.whitespaces) as NSString! 
      self.searchdelegate.hashtag=searchdelegate.hashtag.replacingPercentEscapes(using: String.Encoding.utf8.rawValue) as NSString! 
      let hashtag = self.storyboard?.instantiateViewController(withIdentifier: "hashtag") 
      self.present(hashtag!, animated: false, completion: nil) 
     } 

    } 

} 

enter image description here

+0

更换didSelectRowAtIndexPath方法和使用didSelectRowAt(swift3.0) –

回答

2

使用此方法,它是swift3.0

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 
} 
+0

谢谢@ yogendra但仍然没有选择不能为我工作? – mouni

+0

Mouni ...请检查你的tableView选择是否设置为false .... 在你的视图中添加这些行加载 tableView.allowsSelection = true; – shafi

+0

@shafi我会把你的编码也......但它仍然适用于我! – mouni