my delegate doesn't fire after NSXMLParser loaded - iphone

i have a class that work as xml parser , am trying to create a delegate to fill in my tableView with data after parserDidEndDocument called ,
my parser class :
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
and i used my delegate on my 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
in my app , am invoking the parser and it run well but the problem that the delegate doesn't fire ?!

I can't see where you are actually using your parser class?
At some point, possibly in ResultsViewController (depending on how you are structuring things) you would need something like:
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
From the source provided this is only a best guess

Related

i am not able to pass value from one view controller to another view controller

hi i have problem that i am not able to pass value from one view controller to another view controller through button i implement when i click on button other view appear on iphone screen but the value which i have set not dispay this is the button code
-(IBAction)save:(id)sender
{
nextview *admin = [[nextview alloc]init];
[self presentModalViewController:admin animated:YES];
if (admin.view)
{
admin.fetchname = name.text;
}
[admin release];
}
and this is the nextview.h file
#import <UIKit/UIKit.h>
#interface nextview : UIViewController
{
UILabel *getname;
NSString *fetchname;
}
#property (nonatomic,retain) IBOutlet NSString *fetchname;
#property (nonatomic,retain) IBOutlet UILabel *getname;
#end
and this is the nextview.m file
#import "nextview.h"
#import "ViewController.h"
#implementation nextview
#synthesize getname,fetchname;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
- (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
{
getname.text = self.fetchname;
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#end
The viewDidLoad method is called before you had a chance to assign your NSString value.
That's why you dont see the text in your UIButton.
Try this :
-(IBAction)save:(id)sender
{
nextview *admin = [[nextview alloc] init];
admin.fetchname = name.text;
[self presentModalViewController:admin animated:YES];
[admin release];
}
-(IBAction)save:(id)sender
{
nextview *admin = [[nextview alloc]init];
[self presentModalViewController:admin animated:YES];
if (admin.view)
{
admin.fetchname = name.text;
}
[admin release];
}
You release the instance of nextview right after you assign the name. That can't even work.
By the way, getname and fetchname are really bad chosen names for properties.
You can do something like this.
You can implement the below code in nextView.h
NSString *fetchData;
also property and synthesize this
#property(nonatomic, retain) NSString *fetchData;
implement this on button pressed code
-(IBAction)save:(id)sender
{
nextview *admin = [[nextview alloc] init];
admin.fetchData = name.text;
[self presentModalViewController:admin animated:YES];
[admin release];
}

How to upload photo and photo's description TOGETHER in iphone app?

Here is what I am doing: Allowing the user to upload a photo and two description fields of the photo to MySQL using their iphone app. I have already figured out how to configure the app so that the text from the two description fields are uploaded (using PostURL and an accompanying .php file on my web server).
Where I am running into problems is how to add a photo into the mix, and have the photo AND text fields transmit together into the database into their corresponding columns (image, name, message).
What should my header and implementation files look like? And as an added bonus, what should my .php file look like? Here is how they exist currently, and as an FYI, this only works to transmit text, not the photo.
Header file:
#import <UIKit/UIKit.h>
#define kPostURL #"http://www.example.com/upload.php"
#define kName #"name"
#define kMessage #"message"
#interface FirstViewController : UIViewController<UINavigationControllerDelegate, UIImagePickerControllerDelegate>{
IBOutlet UITextField *nameText;
IBOutlet UITextView *messageText;
NSURLConnection *postConnection;
UIImageView * theimageView;
UIButton * choosePhoto;
UIButton * takePhoto;
}
#property (nonatomic, retain) IBOutlet UITextField * nameText;
#property (nonatomic, retain) IBOutlet UITextView * messageText;
#property (nonatomic, retain) NSURLConnection * postConnection;
#property (nonatomic, retain) IBOutlet UIImageView * theimageView;
#property (nonatomic, retain) IBOutlet UIButton * choosePhoto;
#property (nonatomic, retain) IBOutlet UIButton * takePhoto;
-(IBAction) getPhoto:(id) sender;
-(void) postMessage:(NSString*) message withName:(NSString *) name;
-(IBAction)post:(id)sender;
#end
Implementation file:
#import "FirstViewController.h"
#implementation FirstViewController
#synthesize nameText, messageText, postConnection, theimageView, choosePhoto, takePhoto,postData;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void) postMessage:(NSString*) message withName:(NSString *) name {
if (name != nil && message != nil){
NSMutableString *postString = [NSMutableString stringWithString:kPostURL];
[postString appendString:[NSString stringWithFormat:#"?%#=%#", kName, name]];
[postString appendString:[NSString stringWithFormat:#"&%#=%#", kMessage, message]];
[postString setString:[postString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:postString]];
[request setHTTPMethod:#"POST"];
postConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
}
}
-(IBAction)post:(id)sender{
[self postMessage:messageText.text withName:nameText.text];
[messageText resignFirstResponder];
messageText.text = nil;
nameText.text = nil;
[[NSNotificationCenter defaultCenter] postNotificationName:#"Test1" object:self];
}
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhoto) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
theimageView.image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#end
(^.^)"Hi sorry for my English is not good if someone like correct my redaction I would appreciate this"
Hi you can use (get, post, web services like soap, rest services like json) request.
From my experience if you like to send an image you have to use base64binary this is a string representation of array of bytes because I've never been able to send one array of bytes, but if is string you can send this normal without base64binary.

Give out a NSMutableArray on a texView on another Viewcontroller in objective-C?

I try to save numbers from a textfield on one viewController in a NSMutableArray when I press a button on this viewContoller. (this is working now)
Then i want the numbers give out on a textview which is on a secondViewController but this dont work. When i want to give out the array on the first Viewcontroller it work fine.
Also i cant erase the NSMutableArray with a button on the SecondviewController.
The SecondviewController have the same class like the viewController.
Can someone show me how i can give out an array on a seconviewcontroller?
Hallo,
at the moment i have this:
//ViewController.h:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
NSMutableArray *textViewArray;
}
#property (strong, nonatomic) IBOutlet UITextField *textLable2;
#property (strong, nonatomic) IBOutlet UITextField *textLable1;
- (IBAction)setArrayWithCurrentNumber:(id)sender;
- (IBAction)returnToTextfield:(id)sender;
#end
//this the .m file:
#import "ViewController.h"
#implementation ViewController
#synthesize textLable2;
#synthesize textLable1;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
textViewArray = [[NSMutableArray alloc]init];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setTextLable2:nil];
[self setTextLable1:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)setArrayWithCurrentNumber:(id)sender
{
NSString *string1 = self.textLable1.text;
[textViewArray addObject:string1];
NSMutableArray *array = [NSMutableArray arrayWithArray:textViewArray];
NSString *string2 = [array componentsJoinedByString:#" "];
self.textLable2.text = [NSString stringWithString:string2];
NSLog(#"%#",textViewArray);
}
- (IBAction)returnToTextfield:(id)sender
{
[textLable1 resignFirstResponder];
[textLable2 resignFirstResponder];
}
#end
If you're calling the second view controller from the first one you could set a property on the second one to hold the NSMutableArray or just send it on the initializer.
something like:
- (id)initWithArray:(NSMutableArray *)array {
if (self = [super init]) {
myArray = [array copy];
}
return self;
}
assuming your second view controller has declared NSMutableArray * myArray;
Edit: Adding some more code in here...
// I'll assume you use some kind of UINavigationController to show your content
- (void)showSecondViewController {
SecondViewController * vc = [[[SecondViewController alloc] initWithArray:yourMutableArray] autorelease];
[self.navigationController pushViewController:vc];
}

Help me to understand the answer given

I have problem with UIModalTransitionStylePartialCurl when i rotate the device beacuse the curl is not rotating as i expected and i found the below extract of the answer but i am not able to undertsand.
i am not sure how to create a "rootviewcontroller" Property as told like below
So i am looking for your guidence to proceed further .I am really stuck with this thing for long days...
Thanks for any help:-
The SOURCE CODE I HAVE
//
// ModalViewExampleViewController.h
// ModalViewExample
//
// Created by Tim Neill on 11/09/10.
//
#import <UIKit/UIKit.h>
#interface ModalViewExampleViewController : UIViewController {
UIButton *showDefaultButton, *showFlipButton, *showDissolveButton, *showCurlButton;
}
#property (nonatomic, retain) IBOutlet UIButton *showDefaultButton, *showFlipButton, *showDissolveButton, *showCurlButton;
- (IBAction)showDefault:(id)sender;
- (IBAction)showFlip:(id)sender;
- (IBAction)showDissolve:(id)sender;
- (IBAction)showCurl:(id)sender;
#end
//
// ModalViewExampleViewController.m
// ModalViewExample
//
// Created by Tim Neill on 11/09/10.
//
#import "ModalViewExampleViewController.h"
#import "SampleViewController.h"
#implementation ModalViewExampleViewController
#synthesize showDefaultButton, showFlipButton, showDissolveButton, showCurlButton;
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (IBAction)showDefault:(id)sender {
SampleViewController *sampleView = [[[SampleViewController alloc] init] autorelease];
[self presentModalViewController:sampleView animated:YES];
}
- (IBAction)showFlip:(id)sender {
SampleViewController *sampleView = [[[SampleViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:sampleView animated:YES];
}
- (IBAction)showDissolve:(id)sender {
SampleViewController *sampleView = [[[SampleViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:sampleView animated:YES];
}
- (IBAction)showCurl:(id)sender {
SampleViewController *sampleView = [[[SampleViewController alloc] init] autorelease];
sampleView.rootViewController = self;
[sampleView setModalTransitionStyle:UIModalTransitionStylePartialCurl];
[self presentModalViewController:sampleView animated:YES];
}
- (void)dealloc {
[showDefaultButton release];
[showFlipButton release];
[showDissolveButton release];
[showCurlButton release];
[super dealloc];
}
#end
//
// SampleViewController.h
// ModalViewExample
//
// Created by Tim Neill on 11/09/10.
//
#import <UIKit/UIKit.h>
#class RootViewController;
#interface SampleViewController : UIViewController {
RootViewController *rootViewController;
UIButton *dismissViewButton;
}
#property (nonatomic, retain) IBOutlet UIButton *dismissViewButton;
#property (nonatomic, retain) RootViewController *rootViewController;
- (IBAction)dismissView:(id)sender;
#end
//
// SampleViewController.m
// ModalViewExample
//
// Created by Tim Neill on 11/09/10.
//
#import "SampleViewController.h"
#implementation SampleViewController
#synthesize rootViewController;
#synthesize dismissViewButton;
- (IBAction)dismissView:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (void)dealloc {
[dismissViewButton release];
[super dealloc];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
[self dismissModalViewControllerAnimated:YES];
return YES;
}
#end
UIView Animation: PartialCurl ...bug during rotate?
I too had this issue and somewhat gave up. However, I mentioned my
dilemma to a friend, who encouraged me to look into the child VC's
logic and I recalled a handy trick that I've used to pass data between
parent/child view controllers.
In your flipside view controller, create a "rootViewController"
property. In your parent view controller, when you initialize the
flipside view controller, you set (where "self" is the rootVC):
flipsideController.rootViewController = self;
You then use this for your flipside VC's
shouldAutorotateToInterfaceOrientation method:
-
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{ return interfaceOrientation ==
self.rootViewController.interfaceOrientation;
}
Viola! The flipside view no longer rotates underneath the partially
curled up parent view!
#From the post : In your flipside view controller, create a "rootViewController" property.
#import <UIKit/UIKit.h>
#class ModalViewExampleViewController;
#interface flipSideViewController : UIViewController {
ModalViewExampleViewController *rootViewController;
}
#property (nonatomic, retain) ModalViewExampleViewController *rootViewController;
#end
and in your flipSideViewController's implementation file
#import "ModalViewExampleViewController.h"
#synthesize rootViewController;

Passing data between two ViewControllers Problem

Hi I have two viewControllers.
NewsViewController
#import "SingleViewController.h"
#interface NewsViewController : UIViewController {
}
- (NSString *)getFirstImage:(NSString *)htmlString;
#end
and the implementation file:
#import "SingleViewController.h"
SingleViewController *singleViewController;
#interface NewsPadViewController () <UIActionSheetDelegate>
- (void)loadSubscriptions;
#property (nonatomic, assign) BOOL wrap;
#property (nonatomic, retain) NSMutableArray *items;
#end
#implementation NewsPadViewController
....CODE....
- (void)carouselCurrentItemTapped{
//[self addSubview:articolo];
MWFeedItem *item =[reader.feedItems objectAtIndex:[carousel currentItemIndex]];
NSLog(#"Current Item tappped, index: %d", [carousel currentItemIndex]);
singleViewController.prova.text=#"CIAO";
singleViewController.ciao=#"sample";
[singleViewController.web loadHTMLString:item.summary baseURL:nil];
NSLog(#"conternutio:");
NSLog(singleViewController.ciao);
}
SingleViewController.h
#import <UIKit/UIKit.h>
#interface SingleViewController : UIViewController{
#public
UIWebView *web;
UILabel *prova;
NSString *ciao;
}
#property (nonatomic,retain) IBOutlet UIWebView *web;
#property (nonatomic,retain) IBOutlet UILabel *prova;
#property (nonatomic,retain) IBOutlet NSString *ciao;
#end
and SingleViewController.m
#import "SingleViewController.h"
#implementation SingleViewController
#synthesize web,prova,ciao;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (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
{
[prova setText:ciao];
[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);
}
#end
Why I can't access from NewsPadViewController at object in SingleViewController? Where is my error? thanks
UPADATE
- (void)carouselCurrentItemTapped{
//[self addSubview:articolo];
MWFeedItem *item =[reader.feedItems objectAtIndex:[carousel currentItemIndex]];
NSLog(#"Current Item tappped, index: %d", [carousel currentItemIndex]);
SingleViewController *singleViewController = [[SingleViewController alloc] initWithNibName:#"SingleViewController" bundle:[NSBundle mainBundle]];
singleViewController.prova.text=#"CIAO";
singleViewController.ciao=#"sample";
[singleViewController.web loadHTMLString:item.summary baseURL:nil];
NSLog(#"conternutio:");
NSLog(singleViewController.ciao);
[singleViewController setOpz:#"sample"];
}
I don't see any instantiation of SingleViewController. You have a pointer to it, but I don't see anywhere in your code example where you actually create it.
Somewhere you need something like:
if (!singleViewController) {
singleViewController = [[SingleViewController alloc] init];
}
or
SingleViewController *singleViewController = [[SingleViewController alloc] initWithNibName:#"SingleView" bundle:nil];
or from somewhere else you need to send a message or set an instance variable in NewsViewController that points to an existing instance of SingleViewController.