2012-01-26 13 views
1

現在のビューパーサの代表者に呼び出して、基本的に私は、データが空で、私はある念の..私は、私は次のビューを表示する前に 上で確認したい、このデータを持っていますビューがポップしたい場合、データが空でない場合は、ビューをロードしてナビゲーションスタックに表示する必要があります。のtableView:didSelectRowAtIndexPath:私はいくつかの非常に興味深いロジック行くを持って

私のtableViewで:didSelectRowAtIndexPath:メソッドが選択されたとき、現在の選択ID番号を取得して、関連する値のみに解析するデータの値を制限することができます。

これは私の方法の中でコードがどのように見えるかです。

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    ///... This stuff is for context.. 

      //Get the subview ready for use 
      VSRViewController *vSRViewController = [[VSRViewController alloc] initWithNibName:@"VSRViewController" bundle:nil]; 
      //Sets the back button for the new view that loads (this overrides the usual parentview name with "Back") 
      self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil]; 
      //Pass Title over to subview 
      vSRViewController.title = @"SubModel"; 

      //Selected cell gives restult to the subview or o the parent view to be displayed.. when the view is pushed or poped 
      NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",@"MODEL",cell.textLabel.text]; 
      filterArray = [parsedDataArrayOfDictionaries filteredArrayUsingPredicate:predicate]; 

      //Sets restriction string so that when subCacheData is parsed only values mathching modIdString will be parsed 
      modIdString = [[filterArray valueForKey:@"MODID"] objectAtIndex:0]; //Restricts Mods dataset 

      //This sets which if statment to enter in parserDidEndDocument 
      dataSetToParse = @"ModID"; 
      [self startTheParsingProcess:modCacheData]; 

      //tempModArra is the array I get back from the parser that has had the restriction string applied to it 
      if ([tempModArray count] == 0) { 
       NSLog(@"POPVIEW"); //testing 
       //pop this view to the parent view.. organize all the values that have to be sent back with protocols and delegates 
      }else if ([tempModArray count] != 0){ 

       //Pass the selected object to the new view controller. 
       [self.navigationController pushViewController:vSRViewController animated:YES]; 

       //Check if modIndexPath is same as selected if not remove accessory tick from the subview 
       if (![modIndexPath isEqual:indexPath]){ 
        submodIndexPath = nil; 
       } 
       [vSRViewController subModelCachedData:modCacheData indexPath:submodIndexPath dataSetToParse:@"ICSum" modelArray:filterArray modIndexPath:indexPath]; 

      //..... 
      } 
      } 
    } 
    //... 

このコードは読みやすくするために編集されたが、..私は名前のいくつかを編集したように、他のものの多くは...ので、いくつかの物事が間違っているかもしれない...それで起こっているが、そのは問題ないはずです..

これは私のパーサーデリゲートで起こっていることです。だからthatsの

- (void)parserDidEndDocument:(NSXMLParser *)parser 
{ 
    //.. other stuff up here. 
    if (dataSetToParse == @"ModID") { 
     //This applies the 
     NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",@"ModID",modIdString]; //modIdString restricts results that have been parsed 
     NSArray *filteredArray = [parsedDataArrayOfDictionaries filteredArrayUsingPredicate:predicate]; 

     tempModArray = filteredArray; 

     //what do I do here to get tempModArray back up to tableView:didSelectRowAtIndexPath: method.. this is where I am abit lost. 
    } 

} 

...すべてが唯一の問題は、私は戻ってのtableViewに私temoModArrayを得ることができないということです作品:didSelectRowAtIndexPathを:ので、私は解決策のいくつかの助けの思考を必要としています。

文脈の理由私はこれをやっている理由は、tempModArrayに値がない場合、サブビューに行くときに空のテーブルビューを表示しないように、ユーザーを親ビューに戻したいと思います。選んでいただければ幸いです。私の返信を楽しみにしています。

答えて

1

は私がにtableViewにバックアップtempModArrayを取得するにはここで何をしますか:didSelectRowAtIndexPath:メソッド

短い答え:あなたはしないでください。

didSelectRowはすでにユーザーが行を選択したことをアプリに通知するために仕事をしています。 アプリにはいくつかの作業があります。つまり、新しいView Controllerをデータでプッシュするかどうかを判断します。プッシュしたり、データがあるかどうかを判断したり、ポップしたりしないでください。むしろ、データがない場合は、最初の部分を押し込まないでください。

パーサーがデータを持っているかどうかを知る時点で、たくさんのオプションがあります。 あなたのパーサーデリゲートがあなたのテーブルビューコントローラクラスにないと仮定しています。 することはでき:

  • ポストあなたのテーブルビューコントローラがために聞いているNSNotification、およびデータ、またはノーオペレーションがあるかどうがないかどう詳細ビューコントローラをプッシュすることができるいずれかのリスニング方法。通知で配列を渡すことができます。
  • 詳細ビューコントローラをプッシュし、配列を渡します(テーブルビューコントローラのヘッダーにプロトコルを宣言し、パーサーがそのメソッドにデリゲートを呼び出すようにする)
  • 詳細ビューをプッシュコントローラは直接パーサー(不快の一種)
  • 使用KVO
  • から

IMOプロトコル方法は、(疎結合良い命名有する)、きれいであるが、それら自身のそれぞれ。

+0

私はあなたの2番目の選択肢を持っています。私がやっていることは私のtableviewにあります:didselect ...メソッドは、私がそのメソッドから必要とするindexpathなどのいくつかの一時変数を設定してから、パーサーデリゲートを呼び出して解析を開始します。 parserdidendの中で:私はビューのプッシュまたはポップアップを設定し、データを重複して渡す、今作成している別のメソッドを呼び出すつもりです。助けてくれてありがとう!とても有難い.. –

関連する問題