Ios 如何在iAction内调用PrepareForSegue?

Ios 如何在iAction内调用PrepareForSegue?,ios,segue,ibaction,Ios,Segue,Ibaction,单击登录按钮后,我要做的是在视图控制器之间传递数据,为此,我使用了-prepareforsgue:sender: 问题是: 我无法在方法-prepareforsgue:sender:中使用uide,它表示未声明uide。但是在iAction中声明如下: NSString *uide = jsonData[@"uid"]; -(IBaction)login:(id)sender { //some code here @try { if ([response sta

单击登录按钮后,我要做的是在视图控制器之间传递数据,为此,我使用了
-prepareforsgue:sender:

问题是: 我无法在方法
-prepareforsgue:sender:
中使用
uide
,它表示未声明
uide
。但是在
iAction
中声明如下:

NSString *uide = jsonData[@"uid"];

 -(IBaction)login:(id)sender {        
  //some code here  
 @try {

 if ([response statusCode] >= 200 && [response statusCode] < 300)
        {
            NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

            NSError *error = nil;
            NSDictionary *jsonData = [NSJSONSerialization
                                      JSONObjectWithData:urlData
                                      options:NSJSONReadingMutableContainers
                                      error:&error];

            success = [jsonData[@"success"] integerValue];
            NSString *uide = jsonData[@"uid"];

            if(success == 1)
            {
                 [self performSegueWithIdentifier:@"segue" sender:self];
            } else {

                NSString *error_msg = (NSString *) jsonData[@"error_message"];
                [self alertStatus:error_msg :@"Sign in Failed!" :0];
            }             
        }
    }
    }
  }  
@catch (NSException * e) {
      NSLog(@"Exception: %@", e);
    [self alertStatus:@"Sign in Failed." :@"Error!" :0];
    }

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"segue"]) {
   FirstViewController *secondVC = (FirstViewController *)segue.destinationViewController;
    secondVC.uID = uide; //here I have declaration error, how can I make like an inheritance from the previous method ?
    NSLog(@"uid is : %@",secondVC.uID);
}}
NSString*uide=jsonData[@“uid”];
-(iAction)登录名:(id)发件人{
//这里有一些代码
@试一试{
如果([response statusCode]>=200&&[response statusCode]<300)
{
NSString*responseData=[[NSString alloc]initWithData:urlData编码:NSUTF8StringEncoding];
n错误*错误=nil;
NSDictionary*jsonData=[NSJSONSerialization
JSONObjectWithData:urlData
选项:NSJSONReadingMutableContainers
错误:&错误];
success=[jsonData[@“success”]integerValue];
NSString*uide=jsonData[@“uid”];
如果(成功==1)
{
[self-PerformsgueWithIdentifier:@“segue”发送方:self];
}否则{
NSString*错误消息=(NSString*)jsonData[@“错误消息”];
[自我提醒状态:错误消息:@“登录失败!”:0];
}             
}
}
}
}  
@捕获(N例外*e){
NSLog(@“异常:%@”,e);
[自我提醒状态:@“登录失败”。:@“错误!”:0];
}
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方
{
if([segue.identifier IsequalString:@“segue”]){
FirstViewController*secondVC=(FirstViewController*)segue.destinationViewController;
secondVC.uID=uide;//这里有一个声明错误,我怎样才能像以前的方法一样进行继承?
NSLog(@“uid是:%@”,secondVC.uid);
}}

我已经尝试解决这个问题好几天了,但是没有找到解决方案!有什么想法吗?

您已经在iAction方法中本地声明了NSString*uide。如果要在其他位置使用该变量,则必须全局声明该变量,例如,在.h:

@property NSString *uide;
在您的IBAction中:

[self performSegueWithIdentifier:@"segue" sender:uide];
然后:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSString *uide = (NSString *)sender;

if ([segue.identifier isEqualToString:@"segue"]) {
   FirstViewController *secondVC = (FirstViewController *)segue.destinationViewController;
    secondVC.uID = uide; //here I have declaration error, how can I make like an inheritance from the previous method ?
    NSLog(@"uid is : %@",secondVC.uID);
}} 
你就不能:

[self performSegueWithIdentifier:@"segue" sender:uide]

您是否知道
-prepareforsgue:sender:
方法和
-performsguewithidentifier:sender:
方法是两个不同的方法?即使我以这种方式声明,我也不会获得所需的if值,即:
jsonData[@“uid”]
这是我要从另一个方法检索的内容。Try:uide=[jsonData objectForKey:@“uid”];我得到了这个错误,我认为是由以下原因引起的:
sender:uide
正如您在我的代码中看到的,我有if-else语句。它转到了else(登录失败!)@user3405229,然后问题出在
success=[jsonData[@“success”]integerValue]这一行检查成功的价值是什么,为什么它不是取决于你的逻辑。哦!你从不调用
[self-performsguewithidentifier:@“segue”sender:self];
你想在
-(void)prepareforsgue:(UIStoryboardSegue*)segue sender:(id)中获取一些数据发送者
。这是不可能的!您需要调试部分到部分代码!还有一件事是,响应数据是什么?您从未使用过它…我在放置代码时得到了以下信息:
-[uitabarcontroller setUID::]:未识别的选择器发送到实例0x1da45220异常:-[uitabarcontroller setUID:]:发送到实例0x1da45220的选择器无法识别