由于未捕获的异常“NSInvalidArgumentException”无法识别的选择器发送到实例而终止应用程序

时间:2014-06-19 04:55:48

标签: ios objective-c xcode xcode4.5

我是xcode的新手,请帮我纠正我的代码所在的错误,

-(void)XYZ:(NSString *)id1
{
    id2 = [id1 intValue];
    [self Vehicles:id2];

}

-(NSArray *)Vehicles:(NSInteger) id2
{

    NSString *urlString=[NSString stringWithFormat:@"http://www.xxxx.com/xxxx/vehiclelist.php?uid=%d&format=json",id2];
    NSURL *url=[NSURL URLWithString:urlString];
    NSData *data=[NSData dataWithContentsOfURL:url];
    NSError *error;
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
    NSArray *results = [json valueForKey:@"posts"];
    return results;
}

我从登录vied控制器传递id值,代码为

if(stat!=0&&id2!=0&&[Username length]!=0&&[Password length]!=0)
{
    Services *loc = [[Services alloc] initWithNibName:@"Services" bundle:nil]; 
    loc.modalPresentationStyle = UIModalPresentationCurrentContext;
    loc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:loc animated:YES completion:Nil];
    MyVchicle *about = [[MyVchicle alloc]  initWithNibName:@"MyVchicle" bundle:nil];
    about.modalPresentationStyle = UIModalPresentationCurrentContext;
    about.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:about animated:YES completion:Nil];
    [loc XYZ:id1];
}

提前致谢。

1 个答案:

答案 0 :(得分:0)

要将数据从一个ViewController发送到另一个ViewController,请按照以下步骤操作:

  1. 在DestinationViewController中声明一个变量。
  2. 将SourceViewController中的segue连接到DestinationViewController。
  3. 现在在您的SourceViewController中,编写此函数:
  4.  -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
            {
            DestinationViewController *destController = [segue destinationViewController];
            destController.varName = @"passThisValue";
            }
    
    1. 上面的函数声明了你的destinationViewController,并为我们在上面声明的destinationViewController的变量赋值。
    2. 这应该让你去。希望这会有所帮助。

      您可以参考此链接。

      Passing Data between View Controllers