у меня есть класс, который работает как xml-анализатор, я пытаюсь создать делегат для заполнения моего tableView данными после вызова parserDidEndDocument,
мой класс синтаксического анализатора: DataPareser.h
#import <Foundation/Foundation.h>
#import "resturantModel.h"
@protocol OnPareserDoneDelegate <NSObject>
@required
-(void) dataFormParser:(NSMutableArray *) itemsArray;
@end
@interface DataPareser : NSObject <NSXMLParserDelegate>{
resturantModel * res;
NSString * currentElementName ;
NSString * currentString ;
NSMutableString * name ;
NSString * city ;
NSString * street ;
NSString * phone1 ;
NSString * phone2 ;
NSString * phone3 ;
NSString * phone4 ;
int ID;
id<OnPareserDoneDelegate>onPareserDoneDelegate;
}
@property (nonatomic, assign) id onPareserDoneDelegate;
- (void)loadUrl :(NSString *)url;
@end
DataPareser.m
import "DataPareser.h"
@implementation DataPareser
@synthesize onPareserDoneDelegate;
static NSMutableArray * itemsArray;
- (void)loadUrl:(NSString *)url{
NSURL* nsURL=[[NSURL alloc]initWithString:url];
NSXMLParser* parser=[[NSXMLParser alloc]initWithContentsOfURL:nsURL];
[parser setDelegate:self];
itemsArray=[[NSMutableArray alloc]init ];
BOOL success = [parser parse];
if(success)
NSLog(@"No Errors");
else
NSLog(@"Error Error Error!!!");
}
- (void)parserDidEndDocument:(NSXMLParser *)parser{
//NSLog(@"Number of Resturants Found : %d",[itemsArray count]);
if([itemsArray count]>0){
NSLog(@"parserDidEndDocument");
NSLog(@"%d",[itemsArray count]);
[[self onPareserDoneDelegate] dataFormParser:itemsArray];
}else {
}
[name release];
[city release];
[street release];
[phone1 release];
[phone2 release];
[phone3 release];
[phone4 release];
}
@end
и я использовал свой делегат на моем ResultViewController
ResultViewController.h
#import "resturantModel.h"
#import "SearchViewController.h"
#import "DataPareser.h"
@interface ResultsViewController : UIViewController <OnPareserDoneDelegate,UITableViewDelegate,UITableViewDataSource> {
IBOutlet UINavigationController * navController;
IBOutlet UITableView * table;
NSMutableArray * array;
resturantModel * res;
NSMutableArray *items;
}
@property (nonatomic,retain)IBOutlet UINavigationController * navController;
@property (nonatomic,retain)IBOutlet UITableView * table;
@end
ResultsViewController.m
#import "ResultsViewController.h"
@implementation ResultsViewController
@synthesize table;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
NSLog(@"initWithNibName");
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)dealloc
{
[navController release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
NSLog(@"Result Did Load");
table=[[UITableView alloc]init];
table.delegate=self;
[table reloadData];
[self.view addSubview:navController.view];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark -
#pragma mark OnPareserDoneDelegate deleget methodes
-(void) dataFormParser:(NSMutableArray *) itemsArray {
NSLog(@"dataFormParser");
}
@end
В моем приложении вызывается парсер, и он работает нормально, но проблема в том, что делегат не запускается?!