0

メールアプリに似たものを作成しました。

API からのデータベース コンテンツと上部の検索バーを一覧表示する tableView (メイン)。

検索の場合、検索応答があるビュー (2 番目) を前面に表示し、それを別のテーブルビュー (2 番目) に配置します。

この部分に関してはOKです。

ここで、別のビューへのナビゲーションが必要ですが、「pushViewController:」でセルを選択すると、何も追加されません (「メイン」の tableView で同じことを行い、うまく機能します)。

  • 2 番目のテーブル ビューをデリゲートとデータソースにリンクしました。
  • 「2番目の」ビューの.hに「UINavigationControllerDelegate」を追加しました。

私の2番目のナビゲーションを除いて、すべてうまくいきます。

4

2 に答える 2

0

検索目的とすべてのデータの表示に必要な tableView は 1 つだけです。2つの配列を維持するだけです。最初のファイルには元のデータが含まれ、2 番目のファイルには検索されたデータが含まれます。検索開始時に2番目の配列で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!
}
于 2015-09-04T04:33:06.393 に答える
0

プッシュの直前に、2 番目のナビゲーション コントローラーが null かどうかを確認します。

  NSLog(@" nav con is %@", mySecondNavigationController);
于 2011-05-31T18:05:36.860 に答える