Ich bin neu in iOS
und ich bin nicht in der Lage Daten von einem Controller zu einem anderen zu übergeben. Ich bin nicht in der Lage die Variable in den zweiten View-Controller zum DurchIOS Objective C Gabe von Daten zwischen den Controllern Ansicht
das ist meine Methode für den Zugriff auf I das Empfangen View-Controller einen Delegaten in .h-Datei erstellt habe
.h-Datei des ersten View-Controller (Senden) @interface OtpViewController: UIViewController @property (nicht atomar, stark) NSString * str; @property (stark, nichtatomisch) NSString * tmp; @Eigenschaft (schwach, nichtatomisch) NSString * requestReply;
.m-Datei des ersten View-Controller (Senden)
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(nullable id)sender{
VerifyViewController *loadCtr = (VerifyViewController *)segue.destinationViewController;
loadCtr.delegate = self;
loadCtr.tmpStr = self.tmp;
NSLog(@"--%@",self.tmp);
[loadCtr setotp:self.tmpdict withMobile:_mobiletf.text];
//NSLog(@"otp:%@",[tmpdict valueForKey:@"otp"]);
NSLog(@"mobile:%@",_mobiletf.text);
}
.m-Datei des zweiten View-Controller (Empfangen)
-(void)setotp:(NSDictionary *)dic withMobile:(NSString *)str{
self.stri=[tmpdict valueforkey:@"otp"];
self.stri1=_mobiletf.text;
OtpViewController.[tmpdict valueforkey:@"otp"]=self.stri;
NSLog(@"%@----%@",self.stri,self.stri1);
}
.h-Datei des zweiten View-Controller (Empfangen)
@protocol VerifyViewControllerDelegate <NSObject>
@end
@interface VerifyViewController : UIViewController
@property (nonatomic,strong) NSString *otpStr;
@property(nonatomic,strong) NSString *mobileStr;
@end
eigentlich ich versuche, otp
vom Server zu bekommen, und ich habe die 012 extrahiertin der ersten Ansicht Controller und jetzt muss ich übergeben otp
und die Handynummer aus dem Textfeld zur zweiten Ansicht Controller zur Verifizierung der otp
bitte helfen !!
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString *requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]; // this is json string
// NSError *error;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error]; // you need to convert to dictionary object
NSLog(@"requestReply: %@", jsonDict);
self.tmp=[jsonDict valueForKey:@"otp"] ;
self.str=self.tmp;
NSLog(@"tmp storage inside block:%@",self.tmp);
}] resume];
[ self performSegueWithIdentifier:@"b1" sender:self];
NSLog(@" storage:%@",self.str);
NSLog(@"tmp storage:%@",self.tmp);
}
bei log, was gedruckt wird, die aus Lebenslauf gibt mir
nulldiese
2017-06-01 12:26:45.803 MenuBar[2652:124758] 9047038606
2017-06-01 12:26:45.809 MenuBar[2652:124758] storage:(null)
2017-06-01 12:26:45.810 MenuBar[2652:124758] tmp storage:(null)
2017-06-01 12:26:48.422 MenuBar[2652:124804] requestReply: {
otp = 325106;
success = 1;
}
2017-06-01 12:26:48.422 MenuBar[2652:124804] tmp storage inside block:325106
Bitte beachten Sie Links https://www.infragistics.com/community/blogs/torrey-betts/archive/2014/05/29/passing-data-between-view-controllers-ios-obj-c. aspx oder https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – user3575114
Mögliches Duplikat von [Daten zwischen View Controllern übergeben] (https://stackoverflow.com/questions/5210535/passing-data -between-view-controllers) – Lion