2

FetchVenuesView之前的VenuesIDController. VenuesIDController是 a 中的第二个标签栏项目tabbarcontrollerFetchVenuesView不是标签栏的一部分。

标签栏中的第一项是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;


    }
4

1 回答 1

0

Your init on VenueIDController appears wrong. you're already in an init, so you don't need to create another one. instead you should have self.delegate = self. The vid object you are creating there isn't going to be retained.

于 2012-10-21T15:57:46.677 回答