0

我创建了类似邮件应用程序的东西。桌面选择后导航

tableView(main)列出来自API的数据库内容和顶部的搜索栏。

对于搜索,我带一个视图(第二个)前面有我的搜索响应,我把它放在另一个tableview(第二)。

对于这部分它是确定的。

现在,我想要导航到另一个视图,但是当我用“pushViewController:”选择一个单元格时,没有任何附加内容(我在我的“主”tableView中执行同样的操作并且效果很好)。

  • 我将我的第二个表视图链接到委托和数据源。
  • 我在我的“第二个”视图的.h中添加了“UINavigationControllerDelegate”。

除了我的第二个导航,所有的效果都不错。

+2

请张贴代码只要你有要求人们调试代码的问题。 – PengOne 2011-05-31 17:44:24

+1

如果它崩溃,请添加崩溃日志。 – 2011-05-31 17:50:16

回答

0

前推右,请检查你的第二个导航控制器为空:

NSLog(@" nav con is %@", mySecondNavigationController); 
+0

我的第二个导航控制器是空的。谢谢。 你知道我如何将我的第二个导航控制器链接到我的主视图的导航控制器吗? – Guillaume 2011-05-31 20:12:28

+0

导航控制器与其他任何对象一样,你可以在初始化你的第二个控制器时传递它的引用SecondViewController * vc2 = [[SecondViewController alloc] initWithNavigationController:myNavCon]; ,或者你可以打一个伊娃,并让来电者直接设置它。 vc2.navigationController = myMavCon; – Rayfleck 2011-05-31 20:45:55

0

你只需要搜索的目的和显示所有数据的一个的tableView。只需维护两个数组。第一个包含您的原始数据,第二个包含搜索的数据。作为一个时候搜索开始重新加载tableView与第二阵列,并把所有的数据在其中。像这样你的导航将适用于这两种情况。

斯威夫特:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
    if isSearch == "true" 
    { 
     return self.searchArray.count 
    } 
    else 
    { 
     return self.arr1.count 
    } 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
{ 
    var cell:UITableViewCell? = 
    tableView.dequeueReusableCellWithIdentifier("tableCell") as? UITableViewCell 

    if(cell == nil) 
    { 
     cell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "tableCell") 
     cell!.selectionStyle = UITableViewCellSelectionStyle.None 
    }  
    if isSearch == "true" 
    { 
     var main_string = self.searchArray[indexPath.row] 
     var attributedString = NSMutableAttributedString(string:main_string) 
      attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor(red: 0.0/255.0, green: 168.0/255.0, blue: 255.0/255.0, alpha: 1.0) , range: NSMakeRange(0, string_to_color.length)) 
     name.attributedText = attributedString 
    } 
    else 
    { 
     name.text = self.arr1[indexPath.row] as String 
    } 
    return cell! 
}