我是iOS
的新手,我無法將數據從一個控制器傳遞到另一個控制器。我不能夠訪問在所述第二視圖控制器iOS客觀c在視圖控制器之間傳遞數據
變量這是我傳球方法我已經建立在接收視圖控制器h文件委託
第一個視圖控制器h文件(發送) @interface OtpViewController:UIViewController @property(nonatomic,strong)NSString * str; @property(strong,nonatomic)NSString * tmp; @property(弱,非原子)NSString * requestReply;第一視圖控制器(接收的)第二視圖控制器
-(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文件
.m文件(發送)第二視圖控制器
- (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文件(接收)
@protocol VerifyViewControllerDelegate <NSObject>
@end
@interface VerifyViewController : UIViewController
@property (nonatomic,strong) NSString *otpStr;
@property(nonatomic,strong) NSString *mobileStr;
@end
其實我試圖從服務器得到otp
我已經提取了otp
在第一個視圖控制器,現在我必須通過otp
和手機號碼從文本字段第二視圖控制器驗證otp
請幫助!
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);
}
在日誌無論是打印是出簡歷給我空
這是我的日誌數據
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
請參閱鏈接https://www.infragistics.com/community/blogs/torrey-betts/archive/2014/05/29/passing-data-between-view-controllers-ios-obj-c。 aspx或https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – user3575114
[視圖控制器之間傳遞數據]的可能重複(https://stackoverflow.com/questions/5210535/passing-data視圖間控制器) – Lion