Vishal Avalani
Vishal Avalani

Reputation: 381

tableview loaded before xml parsing is done, data not loaded

When a user clicks a row in Table View it goes to detailed view where XML parsing is done in viewDiDLoad method. The Detail view gets loaded before XML parsing is done owing to which number of rows are zero.

In short, table view gets loaded before XML parsing is complete. How to achieve this? I am facing this issue from quite some time now..

Request help!!

Code of viewDidLoad: -

- (void)viewDidLoad
{
self.title = newsTitle;   
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
xmlParser = [[XMLParser alloc] init];
NSString * tblName = [[NSString alloc] init];
int rowsCount;
rowsCount = 10;
tblName = @"bollywood";
[xmlParser loadMovieData:tblName andRowsCount:rowsCount];  
}

Upvotes: 0

Views: 459

Answers (3)

Parag Bafna
Parag Bafna

Reputation: 22930

Use Delegates. Declare one protocol

@protocol myProtocol
-(Void)didFinishParsing;
@end

Implement this method where you are reloading tableview.

@interface reloadClass <myProtocol> : NSObject{
XMLParser *myParser;
}

   @end
    @implementation reloadClass
    -(void)awakeFromNib
    {
    [myParser setDelegate:self];
    }
    -(void)didFinishParsing
    {
    [mytable reloadData];
    }
    /*your methods*/

Use didFinishParsing method in XML Parser class.

id <myProtocol>delegate;

After Finishing Parsing

[delegate didFinishParsing];

Upvotes: 0

iphonedev23
iphonedev23

Reputation: 991

While connecting your table to IBOutlet don't connect the datasource and delegate with "FileOwner"

you have a xml parser delegate -(void)parserDidEndDocument:(NSXMLParser *)parser set datasource and delegate of table view in this delegate.

Upvotes: 1

EXC_BAD_ACCESS
EXC_BAD_ACCESS

Reputation: 2707

Thru the Delegates you can control this.(ie) send the control to XMLParser classs, Once tha parsing done get bac control to current class and load the detail view.

Upvotes: 0

Related Questions