繁体   English   中英

obj-c委托方法为null

[英]obj-c delegate method is null

FetchVenuesView preceeds的VenuesIDController VenuesIDController处于第二的TabBar项目tabbarcontroller FetchVenuesView不是FetchVenuesView的一部分。

tableview的第一项是一个tableview在其中我可以毫无问题地调用一个委托。 但是,当我尝试在VenuesIDController调用委托时,它总是在日志中显示为null。

我在这里做什么? 我是否可以将代表连接到情节提要中? 怎么样?

我有一个FetchVenuesViewController.h

#import "VenueTableViewController.h" 
#import "VenueIDController.h"

@interface FetchVenuesViewController : UIViewController< VenueTableViewControllerDelegate, VenueIDControllerDelegate>{
    NSDictionary* venueJSON;
    NSDictionary* idJSON;

};

@property (strong) NSDictionary* idJSON;


- (void)VenueFetch;

- (void)IDFetch;


@end

FetchVenuesViewController.m

@synthesize idJSON;

- (void)IDFetch {

    //request some webservice 


    NSData *data = [NSURLConnection sendSynchronousRequest:request
                                         returningResponse:&response
                                                 error:&error];
    //save the response



    if (data) {

        id IDJSON = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
        if (!IDJSON) {
           //handle error

        }
        else {


        //do something

        }



    } else {
        // fetch failed

    }

    activityIndicator.hidden = NO;
}

-(NSDictionary *)getID{
    [self IDfetch];
    NSLog(@"json%@",idJSON);
    return idJSON;
}

VenueIDController.h

@protocol VenueIDControllerDelegate;

@interface VenueIDController : UIViewController{

}


@property (assign) id <VenueIDControllerDelegate> delegate;
-(IBAction)getIDData:(id)sender;

@end

@protocol VenueIDControllerDelegate <NSObject>
-(NSDictionary *)getID;
@end

并在VenueIDController.m

@interface VenueIDController (){
        NSMutableArray* IDData;
        UIImage* IDBarcode;
    }
    -(void) displayIDData:(NSDictionary*)data;
    @end

    @implementation VenueIDController
    @synthesize delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

        VenueIDController *vid = [[VenueIDController alloc] init]; 
        vid.delegate = self;
        NSLog(@"%@",vid);


    }
    return self;
}


    -(void) displayIDData:(NSDictionary*)data{

        [delegate getID];


        NSDictionary* idJSON = data;


    }

initVenueIDController出现错误。 您已经在一个init中,因此您无需创建另一个init。 相反,您应该具有self.delegate = self 您正在创建的vid对象将不会保留。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM