gpt4 book ai didi

iphone - TableView :didSelectRowAtIndexPath: call to current-view Parser delegates

转载 作者:行者123 更新时间:2023-11-29 13:41:30 24 4
gpt4 key购买 nike

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

所以在我的 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];

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

此代码已针对可读性进行了编辑,其中还有很多其他内容..所以有些地方可能是错误的..因为我已经编辑了一些名称..但它应该没问题..

这就是我的解析器委托(delegate)中发生的事情。

- (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: 所以我需要一些帮助来思考解决方案。

同样出于上下文考虑,我这样做的原因是,如果 tempModArray 中没有值,我想将用户发送回父 View ,这样他们在转到 subview 进行选择时就不会看到空 TableView ..希望这一切都有意义..我期待着我们的回复。

最佳答案

what do I do here to get tempModArray back up to tableView:didSelectRowAtIndexPath: method

简短的回答:你不知道。

didSelectRow 已经完成了他的工作,即通知应用程序用户选择了该行。现在应用程序有一些工作要做。也就是说,弄清楚它是否会推送一个带有数据的新 View Controller 。所以不要push,判断有没有数据,然后pop;相反,如果没有数据,请不要一开始就推送。

当你的解析器知道它是否有数据时,你有很多选择。我假设您的解析器委托(delegate)不在您的 TableView Controller 类中。您可以:

  • 发布您的 TableView Controller 正在监听的 NSNotification,如果有数据,监听方法可以推送详细 View Controller ,如果没有,则不执行任何操作。您可以在通知中传递数组。
  • 直接在您的 TableView Controller 上调用一个方法来推送详细信息 View Controller ,传入数组(在您的 TableView Controller header 中声明一个协议(protocol)并让解析器委托(delegate)调用该方法)
  • 直接从解析器推送详细 View Controller (有点恶心)
  • 使用 KVO

imo 协议(protocol)方法是最干净的(松散耦合但命名良好),但每个都是自己的。

关于iphone - TableView :didSelectRowAtIndexPath: call to current-view Parser delegates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9012484/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com