UIPickerView under empty selection [closed] - ios

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
When my UIPickerView View is empty [the array is loads the data from is empty], If I try to select the Picker View the application crashes. What is the solution

I'm not sure but i guess that error generated because your array is empty and you should write any where in delegate method of UIPickerView such like [array objectAtindex....]; so,,
In each statement which you write [array objectAtindex....]; put condition that
if(array.count > 0)
[array objectAtindex....];..
So your picker will open but not generate any error.
EDITED:
I got solution for you:
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if ([myArray count] == 0)
return 1;
return [myArray count];
}
No need to apply any other condition i was checked it, in my project.

It's due to array out of bound exception it seems.
Check whether you are using any static index value while selecting the values.
e.g [sourceArray objectAtIndex:0]; // It get crash when the source array is empty.

Related

What is the best way to use if([names count]>1) in swift? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
In Objective C we used
if([names count]>1){
// array count is greater than one
}
The same way i tried to check in swift. But the complier shouts.
Any idea??
The correct way to write it should be:
if name.count > 1 {
// Your code here
}
Your syntax is incorrect. Brackets are used in Objective-C, not Swift.
Try this:
var shoppingList = ["Eggs", "Milk"]
if(1 < shoppingList.count) {
println( "Greater than one")
}

save string variable in NSMutableArray -Error [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm new to iOS and its development. Here I'm passing string value to saveStringpath variable then I want to save it in type NSMutable array saveStrings but I'm getting:
thread 1 exc_bad_access (code=2 type breakspoint
please help me.
//here i need to save these data in NSMutable array
-(void)saveNSMutablearray:(NSString*)saveStringpath
{
//start Mutable array to save this values
NSMutableArray *saveStrings =[[NSMutableArray alloc]init];
[saveStrings addObject:saveStrings];
NSString *test = [saveStrings objectAtIndex:0];
NSLog(#"JSON:-----vm %#", test);
}
The problem you are facing is because of wrong variable name. In your code you are adding array into array, so to solve the problem please change this line:
[saveStrings addObject:saveStrings];
into that one:
[saveStrings addObject:saveStringpath];
and the problem is gone :)

nsmutablearray addobject adding object.text twice [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
Using addObject is adding the object twice
AppDelegate *appdelegate = [[UIApplication sharedApplication] delegate];
NSLog(#"LOG1 %#", object.text);
[appdelegate.mutarray addObject:object.text];
NSLog(#"LOG2 %#", appdelegate.mutarray);
Log1 returns: LOG1 value
Log2 returns: LOG2 (
"value",
"value"
)
why is it adding in twice? removeObject removes both can i remove just one
Because your first time added your value to NSMutableArray through without remove value from the NSMutableArray going add often. that so far it be adding concurrent duplicate value. before adding new value remove your entire array.
if(appdelegate.mutarray.count!=0)
[appdelegate.mutarray removeAllObject];
[appdelegate.mutarray addObject:object.text];

display NSDictionary to uilables dynamic view [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I have to parse a complicated xml
http://clinicaltrials.gov/show/NCT01423929?displayxml=true
in this xml when I change id NCT01423929 then i got another xml and both of xml tags are not fixed there may be change in number of tag according id.
But I have a an xml schema for above xml
http://clinicaltrials.gov/ct2/html/images/info/public.xsd
for parsing i am using XMLConverter and XMLReader both are return me NSDictionary but I don't get that how to dynamic work with NSDictionary to display keys on left side UILabel and value for that key on right side UILabel I am attached a screen that
Please help and sorry for bad english
Thanks in advance
It's pretty simple as you parse the data from xml.
Lets say your Dictionary name is parseDictionary and it's look something like below..
parseDictionary:
{
"Responsible Party" = "Gilead Sciences";
"Start Date" = "September, 2013";
"Last Updated Date" = "August 20, 2013";
}
You have already did that. Now just do the below
NSArray *keyArray=[parseDictionary allKeys];
for(NSString *key in keyArray)
{
[leftLabel setText:key]; //set the key on the leftLabel
[rightLabel setText:[parseDictionary objectForKey:key]]; //set the value on right label.
}
NB:: For each and every loop it'll over right the values so you will get only the Last Updated Date and August 20, 2013. I am just showing you how to get the key with associated value. I guess you must use UITableView to show the data. So there will no problem for you.

Compare Placeholder Text in text field [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have set the placeholder text(e.g. Under 18s) of a text field(homeTeam) in storyboard. Now i want to check the condition something like below.
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([_homeTeam.text isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[_homeTeam setPlaceholder:#""];
}
}
But the condition is never getting true. What am i missing here? _homeTeam.text is blank when i used NSlog to trace. Why is it so?
Please suggest.
change your if condition, it should be _homeTeam.placeholder not _homeTeam.text because you set placeholder text not a text of UITextField.
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([_homeTeam.placeholder isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[_homeTeam setPlaceholder:#""];
}
}
You actually want to compare against the placeholder property, not text (which is input by the user).
Also, I would instead refer to textField (instead of _homeTeam directly, as you might add other text fields later), as such:
- (BOOL)textFieldShouldBeginEditing:(UITextField *) textField
{
if ([textField.placeholder isEqualToString:#"e.g. Under 18s"]) { // e.g. Under18s
[textField setPlaceholder:#""];
}
}

Resources