How to parse XML array in iPhone? - iphone

I am doing parsing, in my parsearray having only two data number of alerts and number of events these are fine. When we are finding the value like
NSString *alertcount = [[xmlparseArray objectAtIndex:indexPath.row ]objectForKey:#"alerts"];
and assigning these string value into label
mylabel.text = [NSString stringWithFormat:#"%#", alertcount];
same for Events.
then it becomes crash. It says:
index 0 beyond out of empty Array
And these parsing I am using in #RootViewController:
UITableViewController {
}
not using custom cell. In this rootviewcontroller class we are using 7 row(these are constant) and I want to assign at row number 5 the value of alert (i.e. mylabel.text = [NSString stringWithFormat:#"%#", alertcount]) at the right position of cell number 5 same is cell number 6.

Your xmlparseArray might be empty. Check if you have any elements in the array. Pls show the code where you populate the array so that we can have a better idea of where you are going wrong

Related

Recognizing all objects generated by a loop

This question is a bit related to one I posed previously entitled "Recognizing UIButton from a loop".
In this case, I have generated a bunch of UITextFields with a loop. When the value of one of them is changed, I'm able to recognize which textfield it was.
However, I want to then edit every textfield that was generated. Specifically, I get input from the one textfield that was edited, and I want to recalculate the other textfields based on the input and name of the recognized textfield.
How do I call for every one of the other generated, non-edited textfields to be modified?
/Vlad
Since you are already using tags, this is what viewWithTag is used for:
// Get a reference to the textfield with tag 3
UITextField *textField3 = (UITextField *)[self.view viewWithTag:3];
// Calculate your new value
float result = 4.32; // Calculate the value that you want the textfield with tag 3 to display
// Change the contents
textField3.text = [NSString stringWithFormat:#"%f", result];
store the text fields in an array, then when you want to change the value
[self.myTextFieldArray enumerateObjectsUsingBlock:^(UITextField *textField, NSUInteger idx, BOOL *stop){
if (![textField isEqual:theTextFieldThatWasEdited])
textField.text = #"whatever text you want";
}];

Iphone : How to get array value in didSelectRowAtIndexPath?

I am using google Api for custom search and have done the json Parsing. I succesfully retreived the values from JSON and store that data in Dictionary.
NSArray *latestdata = [(NSDictionary*)[responseString JSONValue] objectForKey:#"items"];
Now I have two array in it link and title
titleArray = [latestdata valueForKey:#"title"];
linkArray = [latestdata valueForKey:#"link"];
Now i use the title array to store the title at CellForRowAtIndexpath and i want to use the link for that specified or selected index at DidSelectIndexPathAtRow.
I have already filled the cell by the title array as below
cell.textLabel.text = [title objectAtIndex:indexPath.row];
But now i dont when i select the row at table how can i get the link for that using the link array at didSelectRowAtIndexPath method.
What could be the solution for this.
Try following code at didSelectRowAtIndexPath
NSLog("Value : %#", [title objectAtIndex:indexPath.row]);
I hope title is global array.
You would use the same paradigm you set the title with. You have indexPath.row available to you in didSelectRowAtIndexPath.
My worry with this is ensuring the arrays are in sync. Would you no be better served using a Map for the data? If you are more comfortable, you can store the titles in an array, because parsing that array to build your table is really straight forward. But how do you know the element in each spot in the title array matches its corresponding member of the link array? Are you sure [title objectAtIndex: 1] matches the desired link in [link objectAtIndex: 1]? Key-value coding will harden this and give you an easier to maintain solution in my opinion.
Good Luck.

NSTableView rows using NSArray

I need to Write 4 sections in a table where two of them have only a single row.
So is there any other way i could do it instead of using NSArray for just a single row?
You can create two dimensional array using NSMutablearray
You can access them by using
[[array objectAtIndex: ] objectAtIndex: ]
Hope it helps.....
Dont know from where you are getting the data for your 2 single rows but you could make a switch(indexPath.section)/case or an if(indexpath.section == yoursectionnumber) logic in your cellForRowAtIndexPart delegate method and there you can assign a value to your cell.
As DShah wrote, you can use variables and such for this so you could for example do a cell.textLabel.text = myString;
Where myString is an NSString created by you.

Dynamic initialization of controls in iphone

I am tying to add the values from an array to a number of text boxes in my view. it is possible for me to make it work by implementing
a1.text=[arrayName objectAtIndex:1];
Similarly i am having a1, a2, a3,... a45,... a60,... upto a99
Here "a1" is the outlet of a particular textfield. what i need is that, i have a plenty of controls on my screen. so its not possible for me to add each and every line. is there any way to add the values from the array to the corresponding textboxes.
what i need is to have a loop which will recursively add the values from the array to the textboxes. which implements the following manually written code
a1.text = [arrayName objectAtIndex:1];
a1.text = [arrayName objectAtIndex:2];
...........
a99.text = [arrayName objectAtIndex:99];
can any one help me please...
Thanks in advance,
Shibin
When you create you controls (e.g. textfields) set their tag property to a value that can later be used to determine an index for corresponding value in your array:
for (int index = startTag; index <= endTag; ++index){
UITextField* field = (UITextField*)[view viewWithTag:index]; // or [view viewWithTag:index + someValue];
field.text = [arrayName objectAtIndex:index];
}

How to combine the values of pickerview with textview?

In My Application pressing the submit button i wanted to perform submit operation but i don't know how combine the textview's value with pickerview's value.if it is possible then show me code with example.
How would you like to combine the values, as a string?
If you simply want to combine them in a single string, here's an example of how you can do it:
- (IBAction)submitPressed:(id)sender {
// Load the selected row for the first component in your picker view
// If you have more than one component you may need to look up more
// Also, you may need to translate this number into something more meaningful
// such as what the selected row represents
int selectedRow = [pickerView selectedRowInComponent:0];
NSString *myString = [NSString stringWithFormat:#"%# %d",
textView.text, selectedRow];
// Do something with myString...
}