我有两个viewcontrollers mainVC和drop_downVC。我也有一个名为JSONutils的对象。用户将输入输入到mainVC viewcontroller中的文本字段中,然后在JSONutils中使用方法联系RESTful api,然后返回并分析JSON对象。当JSONutils中的connectionDidFinishLoading方法完成时,我想继续使用drop_downVC视图控制器。一切都在努力达到drop_downVC。从我一直在做的研究看来,使用performSegueWithIdentifier似乎是一条路。所以下面是我试图在JSONutils的connectionDidFinishLoading方法中实现的代码。尝试使用performSegueWithIdentifier在connectionDidFinishLoading完成后继续使用ViewController
//JSONutils.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
//NSLog(@"The receivedData is: %@", receivedData);
//JSON parsing code from here to
//here...
[self performSegueWithIdentifier:@"segue_drop_downVC" sender:self];
}//(void)connectionDidFinishLoading
上面的代码给了我下面的错误。
No visible @interface for 'JSONutils' declares the selector 'performSegueWithIdentifier:sender:'
我google了这个错误,但找不到适用于我的特定解决方案的任何内容。
我创建了segue并使用此post相应地命名了segue标识符(segue_drop_downVC)。
我也一直把下面的代码放在任何地方(JSONutils,mainVC)可能看看是否会改变什么,但它没有。
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
//NSLog(@"The segue identifier is: %@", [segue identifier]);
//if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])
drop_downVC *nextViewController = [segue destinationViewController];
}
我没有在Objective-C多的编程经验,但是当我有我用故事板和原因请看viewcontrollers之间移动。当我使用故事板并继续游戏时,当用户点击一个按钮时,我已经“发现”了。我从来没有等待数据回来,然后导航到下一个视图控制器。我的计划是继续将所有JSON操作和解析方法放入JSONutils文件中。所以我想保留mainVC和drop_downVC这些类型的方法。我一直在做研究,尝试不同的事情,但似乎无法得到它。任何帮助或反馈非常感谢!谢谢。
我刚刚结束了将我的JSONutils方法移动到视图控制器和[self performSegueWithIdentifier:@“segue_drop_downVC”sender:self]像魅力一样工作。是最简单的解决方案。谢谢。 – user2743