数据没有从一个VC传递到另一个VC,我一生无法理解。我试图传递一个NSURL或NSURLRequest,当我注销第二个VC上的request / url对象时,我得到了null。

第一个VC.h

#import <UIKit/UIKit.h>
#import "ILAuthClient.h"
#import "ILAuthLoginViewController.h"

@interface ILViewController : UIViewController

@property (strong, nonatomic) NSString *string;
@property (strong, nonatomic) NSURL *request;
@end

第一个VC.m(相关部分)
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"authLogin"]){
        NSURL *url = [self authenticateWithInstagram];
        ILAuthLoginViewController *authModal = [[ILAuthLoginViewController alloc]init];
        authModal.delegate = self;
        authModal.url = url;}

第二个VC.h
#import <UIKit/UIKit.h>

@interface ILAuthLoginViewController : UIViewController <UIWebViewDelegate>

@property (strong, nonatomic) IBOutlet UIWebView *webView;
@property (strong, nonatomic) NSURLRequest *request;
@property (strong, nonatomic) NSURL *url;
@property (strong, nonatomic) NSString *string;

@end

第二个VC.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.webView.delegate = self;
    self.request = [[NSURLRequest alloc]initWithURL:self.url];

    [self.webView loadRequest:self.request];
    NSLog(@"Request %@", self.request);

}

最佳答案

当您输入prepareForSegue时,已经为您分配了第二个视图控制器,并且可以作为segue上的destinationViewController属性使用。您正在分配一个新对象并分配属性,但未使用该对象。

您的方法应该是

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if ([segue.identifier isEqualToString:@"authLogin"]){
        NSURL *url = [self authenticateWithInstagram];
        ILAuthLoginViewController *authModal = (ILAuthLoginViewController *)segue.destinationViewController;
        authModal.delegate = self;
        authModal.url = url;
   }
}

关于ios - iOS发现数据没有通过,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22982986/

10-08 20:40