我试图VenueIDController
通过实现委托/协议来传递 JSON。但是它似乎不起作用。请让我知道我错过了什么。我什至在 fetch 方法中输入了一个日志,以查看它是否被调用,但它甚至没有记录,这意味着它没有被调用,请帮忙。
我有一个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;
-(void) displayIDData:(NSDictionary*)data{
[delegate getID];
NSDictionary* idJSON = data;
}