user value in textfield become wrong while viewing - ios

I am new to IOS i created textfield for enter value in integer.That integer convert into string then it can be passed to Post method and finally button action it can be viewed in alert view.if user given value to textfield means its value going wrong but constant value is given means its showing correct value i am struggling to get correct value when user enter in textfield.
Post method:
below coding showing post method with parameter(str)passing
-(void) sendDataToServer : (NSString *) method params:(NSString *)str{
NSData *postData = [str dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%lu", (unsigned long)[str length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:URL]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setHTTPBody:postData];
NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:request delegate:self];
if( theConnection ){
mutableData = [[NSMutableData alloc]init];
}
}
picker view:
- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(pickerView.tag ==2){
txtText.text = (NSString *)[arrMsg objectAtIndex:row];
branchid1 = (NSString *)[arrmsg1 objectAtIndex:row];
NSLog([arrmsg1 objectAtIndex:row]);
}else if(pickerView.tag ==1){
currency1.text = (NSString *)[currencyname1 objectAtIndex:row];
currencyid1 = (NSString *)[id1 objectAtIndex:row];
NSLog([id1 objectAtIndex:row]);
}
else
{
currency2.text = (NSString *)[from_currency objectAtIndex:row];
currencyid2 = (NSString *)[id2 objectAtIndex:row];
NSLog([id2 objectAtIndex:row]);
}
//here i assign textfield value into string
fourthstr = [NSString stringWithFormat:#"%d",value1.text];
NSLog(#"%#",value1.text);
//here i created str as string to pass parameter to post method
str = [NSString stringWithFormat:#"branch_id=%#&from_curr=%#&to_curr=%#&value=%#",branchid1,currencyid1,currencyid2,fourthstr];
[self sendDataToServer :#"POST" params:str];
}

Related

IOS:how to get value from dictionary?

In my project I am showing the values of NSMutableDictionary on a UITableview. It works fine. On my UITableView I also have an Edit button. The only thing I want is that when I click on edit button the whole data will show on the next view.
The values which have to shown on edit view will get on the basis of Key- 'id'.
Please help me to how to get the value of Key- 'id'. and use it on the second view to display details.
I am using the following code:
-(void)physiciandata
{
NSString *post = [NSString stringWithFormat:#"data[Users][ref_id]=%#&api_key=bf45c093e542f057c123ae7d6",refidstr];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:#"http://192.168.0.20/hsch/api/user_procedure_list"]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
[request setHTTPBody:postData];
NSString *str=[[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"str : %#",str);
NSDictionary *dict6 = [self cleanJsonToObject:responseData];
//NSLog(#"str : %#",dict6);
physiciandict = [[[dict6 objectForKey:#"procedure"] objectAtIndex:0] objectForKey:#"PhysiciansProcedures"];
physiciandict1 = [[[dict6 objectForKey:#"procedure"] objectAtIndex:0] objectForKey:#"Procedures"];
//diagnosedictforname = [[[dict6 objectForKey:#"diagnoses"]objectAtIndex:0]objectForKey:#"Diagnoses"];
NSLog(#" for ref id =%# , data is= %# , and %# " ,refidstr, physiciandict , physiciandict1);
CompletephyDic = [physiciandict mutableCopy];
[CompletephyDic addEntriesFromDictionary:physiciandict1];
NSLog(#"Complete data is %#",CompletephyDic);
}
and this is the code I put to display data on tableView
{
NSString *strid = [physiciandict objectForKey:#"id"];
serialnmbrphysician.text = #"";
serialnmbrphysician.text = strid;
serialnmbrphysician.backgroundColor = [UIColor lightGrayColor];
NSLog(#"data1 %#",strid);
NSString * strName= [CompletephyDic objectForKey:#"procedure_name"];
procedurename.text = #"";
procedurename.text = strName;
procedurename.backgroundColor = [UIColor lightGrayColor];
NSLog(#"data2 %#",strName);
NSString *strName2 = [CompletephyDic objectForKey:#"procedure_code"];
procedurecode.text = #"";
procedurecode.text = strName2;
procedurecode.backgroundColor = [UIColor lightGrayColor];
NSLog(#"data3 %#",strName2);
NSString *strName3 = [physiciandict objectForKey:#"charge_amt"];
averagemedicareallowedamount.text = #"";
averagemedicareallowedamount.text = strName3;
averagemedicareallowedamount.backgroundColor = [UIColor lightGrayColor];
NSLog(#"data4 %#",strName3);
NSString *strName4 = [physiciandict objectForKey:#"total_amt"];
avgsubmittedchargeamount.text = #"";
avgsubmittedchargeamount.text = strName4;
avgsubmittedchargeamount.backgroundColor = [UIColor lightGrayColor];
NSLog(#"data5 %#",strName4);
NSString *strName5 = [physiciandict objectForKey:#"medicare_amt"];
avgmedicarepaymentamount.text = #"";
avgmedicarepaymentamount.text = strName5;
avgmedicarepaymentamount.backgroundColor = [UIColor lightGrayColor];
NSLog(#"data6 %#",strName5);
}

how to POST UIPickerview Value to JSON url

I have two UITextFields(cityNames,collageNames).I get data for JSON url.I get and Placed data to UIPickerview based on UITextFields. when select cityName that city name placed into UITextFields but now I need that particular index value post to JSON URL and same as collage name
. I know about String value Post to JSON url. But I don't know about How to post UIPickerview Index Value to JSON url.
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSLog(#"select row is %d",row);
if(pickerView.tag==1){
CityName.text = [secondArray objectAtIndex:row];
string1=
[NSString stringWithFormat:#"%d",[yourpicker selectedRowInComponent:0]];
NSLog(#"string ring %#",string1);
}
else if(pickerView.tag==2){
CollageName.text = [firstArray objectAtIndex:row];
string2=
[NSString stringWithFormat:#"%d",[yourpicker selectedRowInComponent:0]];
}
}
String1 and String2 is get IndexValue .But i don't how to pass that particular Stringvalue to JSON.I tired but When i Print String 1 and 2 using NSLog outSide of Did-select Method it's showing null Values.When i Print String values in Didselect method it's showing select Index value
NSString *post =[NSString stringWithFormat:#"?&citynames=%#&collageNames=%#",cityname.text,collagename.text];
or
NSString *post =[NSString stringWithFormat:#"?&citynames=%#&collageNames=%#",string1,string2];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:#"http://192.168.3.35:8090/SaveDollar/rest/users/add"]]];
NSLog(#"getData%#",request);
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Current-Type"];
[request setHTTPBody:postData];
NSLog(#"getData%#",request);
con3 = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if(con3)
{ webData3=[NSMutableData data];
NSLog(#"Connection successfull");
NSLog(#"GOOD Day My data %#",webData3);
}
else
{
NSLog(#"connection could not be made");
}
I tired like this (above code).i not getting.So Please give me any idea about How to post UIPickerView indexValue to JSON Url.
Thanks in Advanced .
You have two different pickerViews so no issue.
Get the actual values from two different arrays as:
NSString *collegeName=[collegeArray objectAtIndex:[self.dataPicker1 selectedRowInComponent:0]];
OR:
If you are able to see textField values, you can use them also as:
NSString *collegeName=collegeTextField.text;
One more way to get index i.e. from textField:
int index=[collegeNameArray indexOfObject:collegeName];
then you can pass index to your urlString.
To get the pickerView selected index use:
[self.dataPicker1 selectedRowInComponent:0]
You can build a urlString as:
urlString=[NSString stringWithFormat:#"?&citynames=%#&collageNames=%#",[self.dataPicker1 selectedRowInComponent:0],[self.dataPicker2 selectedRowInComponent:0]];

Appending two components in a single component in UIPickerView

I had very minute problem since yesterday. I had 2 tables in the database one with Projects and other with Benefits. I want to add the two tables data in Single PickerView Component. For example Projects has pro1, proj2, proj3 and Benefits table has benefits1, benefits2. So I want to append both projects table dat and Benefits table data in a single PickerView component.
-(void)loadprojects
{
NSString *post =[[NSString alloc] initWithFormat:#"username=%#",[self.projectpicker dataSource]];
// Code for Project loading
NSString * BenefitString =#"http://test.com/GetBenefitTypes";
NSURL *Benefiturl = [NSURL URLWithString:BenefitString];
NSString *projecturltemp = #"http://test.com/GetAssignedProjects";
NSString *str = [[NSUserDefaults standardUserDefaults] valueForKey:#"UserLoginIdSession"];
NSString *usrid = str;
NSString * projecturl =[NSString stringWithFormat:#"%#/%#",projecturltemp,usrid];
NSURL *url = [NSURL URLWithString:projecturl];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:Benefiturl];
[request setURL:url];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/projectpicker" forHTTPHeaderField:#"Accept"];
[request setValue:#"application/jsonArray" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
NSURLRequest *urlRequestBenifits = [NSURLRequest requestWithURL:Benefiturl
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
// Make synchronous request
urlData = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
urlData = [NSURLConnection sendSynchronousRequest:urlRequestBenifits
returningResponse:&response
error:&error];
if ([response statusCode] >= 200 && [response statusCode] < 300)
{
NSString *responseData = [NSJSONSerialization JSONObjectWithData:urlData
options:NSJSONReadingAllowFragments error:&error];
NSArray *entries = [NSJSONSerialization JSONObjectWithData:[responseData dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:&error];
if(!entries)
{
NSLog(#"Error : %#", error);
}
else{
for (NSDictionary *entry in entries) {
projID = [entries valueForKey:#"ID_PROJECT"];
projectNames = [entries valueForKey:#"NM_PROJECT"];
BenefitsNames = [entries valueForKey:#"NM_LEAVES"];
}
//Combined = [BenefitsNames arrayByAddingObjectsFromArray:projectNames];
NSLog(#"Combined : %#", projectNames);
//NSLog(#"projID : %#", projID);
_projectpicker.delegate = self;
_projectpicker.dataSource = self;
}
} else {
}
}
Are projects and benefits NSArray instances? If so why not just combine them into one array and use that moving forward?
NSArray *projects = #[#"pro 1", #"pro 2"];
NSArray *benefits = #[#"benefit 1", #"benefit 2"];
NSArray *combined = [projects arrayByAddingObjectsFromArray:benefits];
NSLog(#"Combined: %#", combined);
Combined prints out:
Combined: (
"pro 1",
"pro 2",
"benefit 1",
"benefit 2" )
Then in your - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component method just return the [combined objectAtIndex:row];
base on my understanding, you wanna have something like above? am i correct? so multiple component in a UIPickerView?
if so, 1st thing, you need to set delegations to your ViewController ->
<UIPickerViewDataSource, UIPickerViewDelegate>
then you implement the following methods in your ViewController.m file:
(I assume you have "NSArray *data" for projects and benefits ready...)
//Number of rows to display in each component
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component==0) {
return [self.listOfProjectsOfLeftCol count];
}
return [self.listOfBenefitsOfRightCol count];
}
//Number of columns to display
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
//define what to display in each rows and columns
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if (component==0) {
return [self.listOfProjectsLeftCol objectAtIndex:row];
}
return [self.listOfBenefitsOfRightCol objectAtIndex:row];
}
//when the row is selected , do something...
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component==0) {
//selected items in left column, now write your own code to do something...
}
else {
//selected items in right column, now write your own code to do something...
}
}
Not clear what do you mean by the combine the two component into one.
But I guess you want combination of project and benefit as Project:Benefit
If so u can use following code snippet
NSArray *arrProject=[NSArray arrayWithObjects:#"Project1",#"Project2",nil];
NSArray *arrBenefits=[NSArray arrayWithObjects:#"Benefits1",#"Benefits2",nil];
NSMutableArray *arrCombined=[[NSMutableArray alloc]init];
for(int i=0;i<[arrProject count];i++)
{
[arrCombined addObject:[NSString stringWithFormat:#"%#:%#",[arrProject objectAtIndex:i],[arrBenefits objectAtIndex:i]]];
}
NSLog(#"Combined:%#",arrCombined);
Its gives you result as
Combined:(
"Project1:Benefits1",
"Project2:Benefits2"
)
And then use the arrCombined for the date picker data source

Loading data in Component 2 after selecting component 1 picker View IOS

There are Three components (projects, tasks and sub tasks )in my pickerview when I select project, I was able to get the project name and respective project ID (Project ID is in label). My requirement is I want to send the project ID to NSURL so that I can load the respective tasks that are assigned to that project ID. Here is my Below Code.
ViewDidLoad:
// Code for Tasks loading
NSString *nsTaskurllocal = #"http://test.com/";
NSString *usrid = #"313";
NSString * productIdString =[NSString stringWithFormat:#"%#/%#",[self.lblProjects text],usrid];
NSLog(#"aString : %#", productIdString);
NSString *aString = [nsTaskurllocal stringByAppendingString:productIdString];
NSURL *nstaskurl = [NSURL URLWithString:aString];
NSLog(#"nstaskurl : %#", nstaskurl);
NSData *nstaskpostData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *nstaskpostLength = [NSString stringWithFormat:#"%lu", (unsigned long)[nstaskpostData length]];
NSMutableURLRequest *nstaskrequest = [[NSMutableURLRequest alloc] init];
[nstaskrequest setURL:nstaskurl];
[nstaskrequest setHTTPMethod:#"POST"];
[nstaskrequest setValue:nstaskpostLength forHTTPHeaderField:#"Content-Length"];
[nstaskrequest setValue:#"application/projectpicker" forHTTPHeaderField:#"Accept"];
[nstaskrequest setValue:#"application/jsonArray" forHTTPHeaderField:#"Content-Type"];
[nstaskrequest setHTTPBody:nstaskpostData];
NSError *nstaskerror = [[NSError alloc] init];
NSHTTPURLResponse *nstaskresponse = nil;
NSData *nstaskurlData=[NSURLConnection sendSynchronousRequest:nstaskrequest returningResponse:&nstaskresponse error:&nstaskerror];
NSURLRequest *nstaskurlRequest = [NSURLRequest requestWithURL:nstaskurl
cachePolicy:NSURLRequestReturnCacheDataElseLoad
timeoutInterval:30];
// Make synchronous request
nstaskurlData = [NSURLConnection sendSynchronousRequest:nstaskurlRequest
returningResponse:&nstaskresponse
error:&nstaskerror];
if ([nstaskresponse statusCode] >= 200 && [nstaskresponse statusCode] < 300)
{
NSString *nstaskresponseData = [NSJSONSerialization JSONObjectWithData:nstaskurlData
options:NSJSONReadingAllowFragments error:&nstaskerror];
NSArray *nstaskentries = [NSJSONSerialization JSONObjectWithData:[nstaskresponseData dataUsingEncoding:NSUTF8StringEncoding]
options:0 error:&nstaskerror];
if(!nstaskentries)
{
NSLog(#"Error : %#", nstaskerror);
}
else{
for (NSDictionary *nstaskentry in nstaskentries) {
taskID = [nstaskentries valueForKey:#"ID_TASK"];
taskNames = [nstaskentries valueForKey:#"TASk_NAME"];
//NSLog(#"Error : %#", taskNames); //log to see the result in console // by Kiran
}
_projectpicker.delegate = self;
_projectpicker.dataSource = self;
}
} else {
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSNumber *myProjectArrayString = [projID objectAtIndex:row];
//NSNumber *myTaskArrayString = [taskID objectAtIndex:row];
//NSLog(#"%#",myArrayString);
//NSLog(#"%#",myTaskArrayString);
lblProjects.text = [NSString stringWithFormat:#"%#",myProjectArrayString];
//lblProjects.hidden = YES;
lblTasks.text = [taskNames objectAtIndex:[pickerView selectedRowInComponent:1]];
//lblTasks.text = [NSString stringWithFormat:#"%#", myTaskArrayString];
lblSubTasks.text = [subtaskNames objectAtIndex:[pickerView selectedRowInComponent:2]];
}
Thanks in Advance
Kiran Kumar
You need to differentiate between your total data, and your displayed data.
So, download all of your data and save it in projectNames, taskNames and subtaskNames. But also have 2 other properties: currentTaskNames and currentSubtaskNames (you don't need
cProjectNames because the user can always see all project names.
After the download:
self.currentTaskNames = taskNames;
self.currentSubtaskNames = subtaskNames;
Now, when the user selects a project, filter the tasks and subtasks that are available.
switch (component) {
case 0:
{
NSString *project = [projectNames objectAtIndex:row];
self.currentTaskNames = [taskNames filteredArrayUsingPredicate:...];
break;
}
case 1:
{
NSString *task = [taskNames objectAtIndex:row];
self.currentSubtaskNames = [subtaskNames filteredArrayUsingPredicate:...];
break;
}
case 2:
// do something interesting
break;
}
You need to fill in the predicates which filter out the tasks and subtasks that aren't appropriate based on the selected project and task.
Also, stop using labels for data storage...

NSXML XML Parsing issue iOS

I know that there are plenty of questions that have been asked and answered and non of them pertain to my problem.
I am posting XML to a server and I get a response back. My problem is getting a specified key back from the response.
I am trying to list all Genders e.g Male, Female and their id's however when parsing the XML into text with NSXML I only get back the Female and ID 2 and I do not get back Male?
I have researched and tried to fix this issue but to no avail.
here is my code:
- (void)getGender {
NSString *soapMessage = [NSString stringWithFormat:
#"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
"<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:app=\"http://app.ws.api.bells.wigroup.com/\">"
"<soap:Header/>\n"
"<soap:Body>\n"
"<app:getAllGenders>\n"
"<request>\n"
"<apiCredentials>\n"
"<apiId>IPHONE_APP</apiId>\n"
"<sha1Password>8656cafcd71cbbfe773a0fdb6c422666a80e5b8f</sha1Password>\n"
"</apiCredentials>\n"
"<request>\n"
"</request>\n"
"</request>\n"
"</app:getAllGenders>\n"
"</soap:Body>\n"
"</soap:Envelope>\n"
];
NSLog(#"Message%#",soapMessage);
NSURL *url = [NSURL URLWithString:#"http://qa.wigroup.co:8080/bells/AppWS"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *msgLength = [NSString stringWithFormat:#"%d", [soapMessage length]];
[theRequest addValue: #"text/xml; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
//[theRequest addValue: #"http://" forHTTPHeaderField:#"SOAPAction"];
[theRequest addValue: msgLength forHTTPHeaderField:#"Content-Length"];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody: [soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
NSURLResponse *response;
NSError *error;
NSData *urlData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error];
NSString *str=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(#"Login response XML:%#",str);
// create and init NSXMLParser object
XmlArrayParser *parser = [[XmlArrayParser alloc] initWithData:urlData];
parser.rowElementName = #"return";
parser.elementNames = [NSArray arrayWithObjects:#"response", #"responseCode", #"responseDesc", #"gendersList", nil];
parser.attributeNames = [NSArray arrayWithObjects:#"id", #"gender", nil];
if ([parser.rowElementName isEqualToString:#"responseCode"] && _flag)
{
//read the value here
NSLog(#"flagging");
}
// parsing...
BOOL success = [parser parse];
// test the result
if (success)
{
NSMutableArray *loginAuth = [parser items];
// self.textView.text = [NSString stringWithFormat:
// #"This is an array of dictionaries, one dictionary for each user:\n\n%#",
// [users description]];
// NSDictionary *eventLocation = [NSDictionary dictionaryWithObjectsAndKeys:#"response", nil];
NSDictionary *loginResponse = [loginAuth objectAtIndex:0]; // this retrieves the first user
NSString *userResponse = loginResponse[#"gendersList"]; // this retrieves that user's username in Xcode 4.5 and greater
NSString *userRes = [loginResponse objectForKey:#"id"];
NSString *test = [loginAuth description];
NSLog(#"Returned Code loginResponse %#",loginResponse);
NSLog(#"Returned Code userResponse %# %#",userResponse, userRes);
NSLog(#"Returned Code test %#",test);
NSMutableArray *array=[[NSMutableArray alloc]initWithCapacity:10];
for (NSDictionary *defineXMLData in loginAuth) {
NSNumber * responseCode = [defineXMLData objectForKey:#"responseCode"];
NSArray * responseDEsc = [defineXMLData objectForKey:#"responseDesc"];
NSArray * genderList = [defineXMLData objectForKey:#"gendersList"];
// NSArray * gender = [defineJsonData objectForKey:#"gender"];
NSLog(#"Genders%#", genderList);
[array addObject: responseCode];
[array addObject: responseDEsc];
[array addObject: genderList];
//[array addObject: gender];
// [array addObject: vouchersUser];
}
label.numberOfLines = 2000; // for example
label.lineBreakMode = NSLineBreakByClipping;
NSString *output=[array componentsJoinedByString:#","];
label.text = [NSString stringWithFormat:#"XML Result: %# ",output];
[SVProgressHUD dismiss];
// [[[UIAlertView alloc] initWithTitle:nil
// message:[NSString stringWithFormat:#"No errors - user count : %i", [[parser items] count]]
// delegate:nil
// cancelButtonTitle:#"OK"
// otherButtonTitles:nil] show];
}
else
{
NSLog(#"Error parsing document!");
// [[[UIAlertView alloc] initWithTitle:nil
// message:#"Error parsing document!"
// delegate:nil
// cancelButtonTitle:#"OK"
// otherButtonTitles:nil] show];
}
}
else
{
NSLog(#"theConnection is NULL");
}
NSLog(#"test");
}
And the XML I get back from my nslog:
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getAllGendersResponse xmlns:ns2="http://app.ws.api.bells.wigroup.com/">
<return>
<responseCode>-1</responseCode>
<responseDesc>Success</responseDesc>
<response>
<responseCode>-1</responseCode>
<responseDesc>Success</responseDesc>
<gendersList>
<gender>Male</gender>
<id>1</id>
</gendersList>
<gendersList>
<gender>Female</gender>
<id>2</id>
</gendersList>
</response>
Is only parsing:
{
gendersList = Female2;
responseCode = "-1";
responseDesc = Success;
}
You have not correctly pointed the problem. Your code parses the whole document, but you keep only the last items (last genderList, last responseCode, last responseDesc). Initialize an array and in your for loop add each dictionary to that array when parsed.

Resources