How to display a multiple values in textfield? - iphone

I'm new to the iPhone. I have four number buttons like 1,2,3,4. When I click any button the value is displayed in a textfield, but when I click two buttons only one value is displayed in textfield.
How to display in multiple values in textfield?

You can add new string value to already displayed value in your text field, for example, in following way:
UITextField *field; // <- reference to your UITextField
NSString *value = [[NSNumber numberWithInt:1] stringValue]; // <- value to add
field.text = [NSString stringWithFormat:#"%#%#", field.text, value];

Related

Each button click adds text to current label objective-c

I'm new to the Objective-c language. I'm trying to create an app that has a button and a label. The button should display some text which I did already. The only problem is that when I click the button, it only adds the specified text once. I want it to keep adding the same text to the label each I time I press the button.
Here is my .h file
{
IBOutlet UILabel *label;
}
-(IBAction)btnClcik:(id)sender;
Here is the .m file
-(IBAction)btnClcik:(id)sender
{
label.text=#"test";
}
To append to the existing text, use the string's concatenation method...
label.text = [label.text stringByAppendingString:#"test"];
You need to append to the string?
Then do
label.text = [label.text stringByAppendingFormat:#"%#", textToAdd];
where textToAdd is a NSString or some other valid object where %# is the correct format specifier.

How to find out programmatically added textfields in a scrollview

Inside my scrollView i am adding uitextfields programmatically by clicking an "ADD" Button. the number of textfields depending on how much i press in add button. it can be 'N' number of textfields.
After this fields editing how can i get values inside the all textfields into an array.
if once i edited textfield there is a possibility to delete entry inside that. So what is the way to save values in the all text fields while clicking in Save button.
i am attaching my screenshot with this.
Thanks in Advance
use fast enumeration.
NSMutableArray *arr = [NSMutablearray....];
for (UIView *subV in self.view.subviews){
if([subV isKindOfClass:[UITextField class]]){
//store it in a NSDictionary, so later can still know which
//textField your text belongs,
NSDictionary *tempDic = [NSDictionary dictionaryWithObjectAndKey:subV.txt
,subV.tag,/*or subVw.placeholder*/,nil];
[arr addObject:tempDic];
}
}
You can get all the textfields by iterating through the subview array of the scrollview
for (UIView *subView in scrollview) {
//check if the subView is a textfield by for example matching a certain tag
//save text of textfield
}
When you are creating textField then assign tagValue to every textField and then access textField using tag value....
UITextField *txtField = (UITextField *) [scrollView viewWithTag:tag];

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";
}];

How to generate UITextFields dynamically with different name and accessing it from another place?

I have an iPhone application in which there are dynamically generated textfields to capture a value of product quantity. The default quantity is 1. I have generated textfields like this
for(int i=0;i<[array count];i++)
{
UITextField *i=[[UITextField alloc]init];
i.frame=CGRectMake(90, Yposqtytextfield, 60, 30);
i.borderStyle=UITextBorderStyleRoundedRect;
[self.scrollview addSubview:i];
i.delegate=self;
i.text=#"1";
i.tag=i;
[appDelegate.qtyArray addObject:i.text];
}
But I want values of quantities in next page. For that I have taken this qtyarray. Now the user is allowed to change quantity. So how can I change the value of quantity in the array. as declaration of textfield is local to that loop. So at next page navigation how can i get the values of all these textfields?
UITextField *aField = (UITextField*)[appDelegate.qtyArray objectAtIndex:0]
it should be
NSString *aValue = [appDelegate.qtyArray objectAtIndex:0];
because he is adding value of textfield not the textfield object itself.
you can access your qtyArray anywhere in the application. Since application delegate is singleton class. You can access value like this
NSString *aValue = [appDelegate.qtyArray objectAtIndex:0];

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...
}