tableView:didSelectRowAtIndexPath:调用当前视图Parser委托

我有一些非常有趣的逻辑去,基本上我有这个数据,我想检查之前,我显示下一个视图..以防万一数据是空的我想popup视图,如果数据不是空的,那么我想加载视图以将其显示在导航堆栈上。

所以在我的tableView:didSelectRowAtIndexPath:方法中,当做出select时,获取当前的selectID号,这样我就可以限制数据Im的值去parsing到相关的值。

这就是我的方法里面的代码。

#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]; //..... } } } //... 

这个代码已经被编辑为可读性,有很多其他的东西在进行..所以有些事情可能是错误的..因为我编辑了一些名称..但它应该是罚款..

这是我的parsing器委托中发生的事情。

 - (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. } } 

所以这就是它..一切工作唯一的问题是,我不能让我的temoModArray回到tableView:didSelectRowAtIndexPath:所以我需要一些帮助思考一个解决scheme。

也是为了上下文,我这样做的原因是,如果tempModArray中没有值,我想发回用户回到父视图,所以他们没有看到一个空的tableview去子视图做出select..希望这一切都是有道理的。我期待着我们的答复。

我在这里做什么来获取tempModArray备份到tableView:didSelectRowAtIndexPath:方法

简短的回答:你不。

didSelectRow已经完成了他的工作,即通知应用程序用户select了该行。 现在应用程序有一些工作要做。 也就是说,看看是否要用数据推送一个新的视图控制器。 所以不要推,决定是否有数据,然后popup; 相反,如果没有数据,不要推到第一位。

在你的parsing器知道它是否有数据的地方,你有很多select。 我假设你的parsing器委托不在你的表视图控制器类。 您可以:

  • 发布表视图控制器正在侦听的NSNotification,如果有数据,侦听方法可以推送详细视图控制器;如果没有数据,则可以不执行。 您可以在通知中传递数组。
  • 在表视图控制器上直接调用一个方法来推送详细视图控制器,传入数组(在表视图控制器头中声明协议,并将parsing器委托调用放入该方法中)
  • 直接从parsing器(一种icky)推动详细视图控制器
  • 使用KVO

协议方法是最干净的,(松散的耦合,但具有良好的命名),但各自为政。