UITabelView reloaded from NSXMLParser (iphone SDK 4.0) - iphone

I am creating application that simply reads data from an XML file and displays it in a table view.
I created a "refresh" button when clicked i want it to redownload the xml file and display it again however it seems to crash my application if there is a XML file already downloaded.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
ipb = [[IPB alloc] init];
sectionTitle=[[NSMutableArray alloc]init];
currentURL=#"http://localhost:8888/xml/Sinnergy.xml";
[self reloadTableView];
[window makeKeyAndVisible];
return YES;
}
-(void)reloadTableView
{
pathURL = [NSURL URLWithString:currentURL];
parser = [[NSXMLParser alloc] initWithContentsOfURL:pathURL];
[parser setDelegate:self];
[parser parse];
[mainTableView reloadData];
}

You are leaking the parser, and if its an instance variable it might cause issues. You should go
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:pathURL];
[parser setDelegate:self];
[parser parse];
[parser release];
Also you are asking the parser to start parsing, but at that point of time you shouldn't be reloading the table, it should be in your
- (void)parserDidEndDocument:(NSXMLParser *)parser
delegate method. Try that and if it still crashes post the crash report

Related

didFinishLaunchingWithOptions doesn't find any rootcontroller

I need to parse some XML that triggers an NSURLConnection. After the parsing finished, I receive some data and then I set the root view controller. My problem is that application:didFinishLaunchingWithOptions: returns before the composeRootController method and an error occurs because the application cannot find any root view controller. How can I wait until composeRootController returns?
My code is the following:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self xmlConnect];
return YES;
}
here xmlConnect function is implemented for parsing
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//convertim la data a string
NSString *receivedDataAsString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(#"connectionDidFinishLoading %#", receivedDataAsString);
//xml parsing
xmlParser = [[NSXMLParser alloc] initWithData:receivedData];
[xmlParser setDelegate:self];
self.receivedData = nil;
BOOL success = [xmlParser parse];
if(success)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
[self composeRootController];
}
here composeRootController sets rootcontroller
Put your
[self composeRootController];
inside
didFinishLaunching...
And have composeRootController call xmlConnect.
You might have to move the xmlConnect method out of your app delegate.

iPhone .ipa file goes blank after opening splash screen?

I have created Map application and it is running on my mac machine with xcode. But when I created its ipa file and sync with my iPhone device it does not open. Only splash screen
get open and getting close. I have my developer and distribution certificate sign with device UDID. My client also could not able to run the application remotely....thanks in advance for your help. plz suggest what I am missing here??
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//sleep(0.5);
arrayNo = [[NSMutableArray alloc] init]; //pickerview radius array
[arrayNo addObject:#"5km"];
[arrayNo addObject:#"10km"];
[arrayNo addObject:#"15km"];
[window addSubview:[viewController view]];
[window makeKeyAndVisible];
return YES;
}
Upadated: with leaks problems
I am also checking the possibility with memory leaks and using instrument tool I am getting 100% leaks at the time of launching the application. Its NSPlaceholderString leaks on following code...
CLLocationCoordinate2D location;
NSString *url = [NSString stringWithFormat:#"..myurl......lat=%f&lng=%f&radius=5",locationManager.location.coordinate.latitude,locationManager.location.coordinate.longitude];
radiusinurl.text = #"5km";
NSURL *URL = [NSURL URLWithString:url];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
//Initialize the delegate.
**XMLParser *parser = [[XMLParser alloc] initXMLParser];** //5.3% leaks
//Set delegate
[xmlParser setDelegate:parser];
//Start parsing the XML file.
**BOOL success = [xmlParser parse];** //0.2% leaks
[xmlParser release];
[parser release];
if(success)
{
NSLog(#"show me [appDelegate.markers count] %d",[appDelegate.markers count]);
annobjs = [[NSMutableArray array] retain];
if([appDelegate.markers count] == 0)
{ //99% leaks on below line where I am calling another method
**[self performSelector:#selector(showingThreeResultsOnCurrentLocation) withObject:nil];** //99% leaks
}
else
{//some logic
}
}
else
{
//logic
}}}}
I have commented leaks at the end of line. Can you correct my code. Thanks in advance...
Initialize view controller first
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; //This is for autoresize when in phone call mode(which does not work yet)
[dict setObject:#"trigger" forKey:#"frame"];
[[NSNotificationCenter defaultCenter] postNotificationName:#"trigger"
object:self
userInfo:dict];
arrayNo = [[NSMutableArray alloc] init]; //pickerview radius array
[arrayNo addObject:#"5km"];
[arrayNo addObject:#"10km"];
[arrayNo addObject:#"15km"];
viewController = [[UIViewController alloc] initWithNibName:#"UIViewController" bundle:nil];
UINavigationController *nav = [[UINavigaitonController alloc] initWithRootViewController:nav];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}

rss read iphone/ipad app

I have an error while reading XML files for my iPhone app. I have a new feature on my iPhone app that reads my RSS feed. Everything looks good by but I have this issue:
Error while loading rss. Please check your Internet connection
Here's my code:
- (BOOL) readRSS {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
BOOL success = NO;
NSXMLParser *parser = nil;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"http://rss.domain.com/%#.xml", self.currentPage]];
parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[parser setDelegate:self];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
success = [parser parse];
[parser release];
[pool drain];
return success;
}
Then I have this code:
- (void) cleartbl:(NSInteger)type {
[[[self rssParser] rssItems] removeAllObjects];
[_tableView reloadData];
if(type == 1) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"RSS Feed"
message:#"Error while loading rss. Please check your Internet connection."
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles: nil];
[alert show];
[alert release];
}
Then i assign:
if([elementName isEqualToString:#"title"]){
self.currentItem.title = self.currentItemValue;
}
What is my issue, am I missing something?
The code provided looks good for me, what I would do first is to check if your RSS is valid. I think you have an RSS issue here. You can use the RSS Validation to make sure everything looks good.
I would recommend to sanitize your RSS, keep it very simple, if you only want to display news or articles use letters and numbers in your text and use SEO friendly URLs.
This will simplify the data you are loading from your app and avoid errors like special characters.
Try with a simple RSS with one entry to start and you will see if your code has errors.

How to show load bar in ipad app while data is fetching from xml after default png is shown

I am fetching XML data from server i want that when data is loading in progress i show a loading bar with default screen this is code in appDidFinishing
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
RootViewController * rootViewController = [[RootViewController alloc] initWithNibName:#"RootViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[self.window addSubview:navigationController.view];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(55, 67, 100, 100)];
[self.activityIndicator startAnimating];
[self.window addSubview:self.activityIndicator];
[self loadXMlTwo];
[self loadXMlMain];
[self performSelectorInBackground:#selector(loadXMlOne) withObject:nil];
[self.activityIndicator removeFromSuperview];
[window makeKeyAndVisible];
return YES;
}
-(void)loadXMlMain{
NSURL*url= [[NSURL alloc]initWithString:#"http://46.137.28.14/app/ipadApplic/working.xml"];
NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
//Initialize the delegate.
XMLParser *parser = [[XMLParser alloc] initXMLParser];
//Set delegate
[xmlParser setDelegate:parser];
BOOL success = [xmlParser parse];
if(success)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
}
-(void)loadXMlOne{
NSURL*url1=[[NSURL alloc] initWithString:#"http://46.137.28.14/app/ipadApplic/rowone.xml"];
NSXMLParser *xmlParserRow = [[NSXMLParser alloc] initWithContentsOfURL:url1];
//Initialize the delegate.
RowOneParser *parser1 = [[RowOneParser alloc] initXMLParser];
//Set delegate
[xmlParserRow setDelegate:parser1];
BOOL success1 = [xmlParserRow parse];
if(success1)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
}
-(void)loadXMlTwo{
NSURL*urlRowTwo=[[NSURL alloc] initWithString:#"http://46.137.28.14/app/ipadApplic/rowtwo.xml"];
NSXMLParser *xmlParserRowTwo = [[NSXMLParser alloc] initWithContentsOfURL:urlRowTwo];
//Initialize the delegate.
RowTwoParser *parserRowTwo = [[RowTwoParser alloc] initXMLParser];
//Set delegate
[xmlParserRowTwo setDelegate:parserRowTwo];
BOOL successRow = [xmlParserRowTwo parse];
if(successRow)
NSLog(#"No Errors");
else
NSLog(#"Error Error Error!!!");
}
What you need to do is unblock your main thread while you are doing background fetch of xml data. Easiest way to do that is add your fetch operations in NSOperationQueue. Set up delegates for the class which fetches the xml and handle the response.

iPhone XML Parser - [c setImage:[attributeDict objectForKey:#"img"]]; WARNING

Hi I am having issues with the following and it crashes the iPhone simulator, while the script has no errors it did bring up one warning in this script.
[c setImage:[attributeDict objectForKey:#"img"]];
The warning is
City may not respond to -setImage:
I am not sure what I have done wrong here is the fill source code.
#import "LocationsParser.h"
#implementation LocationsParser
#synthesize managedObjectContext;
-(id) initWithContext: (NSManagedObjectContext *) managedObjContext
{
self = [super init];
[self setManagedObjectContext:managedObjContext];
return self;
}
- (void)parseXMLFileAtURL:(NSURL *)URL parseError:(NSError **)error
{
// /Applications/MyExample.app/MyFile.xml
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
// Set self as the delegate of the parser so that it will receive the parser delegate methods callbacks.
[parser setDelegate:self];
// Depending on the XML document you're parsing, you may want to enable these features of NSXMLParser.
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser setShouldResolveExternalEntities:NO];
[parser parse];
NSError *parseError = [parser parserError];
if (parseError && error) {
*error = parseError;
}
[parser release];
}
-(void) emptyDataContext
{
// Get all counties, It's the top level object and the reference cascade deletion downward
NSMutableArray* mutableFetchResults = [CoreDataHelper getObjectsFromContext:#"County" :#"Name" :NO :managedObjectContext];
// Delete all Counties
for (int i = 0; i
use this
[c setImage:(id)[attributeDict objectForKey:#"img"]];
c - what is it? E.g., if it is supposed to be UIImageView, you can do so:
[(UIImageView *)c setImage:[attributeDict objectForKey:#"img"]];