2011-08-16 6 views
0

をロードした後、私の代理人は、私は、parserDidEndDocumentと呼ばれる後のデータと私のtableViewを埋めるために、デリゲートを作成しようとしています、XMLパーサとして動作するクラスを持って発生しません NSXMLParserは

私のパーサクラス: DataPareser。時間

#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 

、パーサを呼び出し、それがうまく実行しますが、デリゲートは発生しません問題ですか?!

答えて

0

実際にパーサークラスを使用している場所がわかりません。これが唯一の最良の推測

で提供されるソースから

DataPareser *dataParser = [[DataPareser alloc] init]; // Create an instance of parser 
dataParser.onPareserDoneDelegate = self;    // Set the delegate to this class 
[dataParser loadUrl:urlToLoad];      // Start doing your work 

:あなたのようなものが必要になりResultsViewControllerでおそらくいくつかの時点で

、(あなたは物事を構築しているかによって異なります)