how to make all fields clear when application starts iphone - iphone

I've 5 labels and 2 text fields in my iphone application when i end the application and restarts it the label and text fields will contain perviously used data. I want to make it clear all labels and text fields when application starts please any one help me Thanks in Advance.

Set the value of the fields as nil in ViewWillAppear or in ViewDidLoad methods.

Try adding this to your code:
textFieldname.stringValue = #"";

Do this in viewwillappear method:
label.text = #""; //and all other labels
txt.text = #""; //and all other textFields

Set the value of fields and labels nil i.e label.text = #""; in ViewWillAppear it'll clear fields and labels when come back to tab.

Related

PrepareForSegue method to pass texts from two different textview into textview in the next view

I am having a trouble on exporting text data. I have a view contains over 3 different uitextview that allow user to type in data. Then i want to export these texts from the 3 different uitextview (e.g. textview1, textview2 and textview3) into a new uiviewcontroller that contains only one uitextview. I also want the textview 1-3 are placed in order. So that the new uitextview will have three different sections in the order of 1-3. I am using PrepareFroSegue method. How should i code this? Many thanks!
What you want to do is concatenate (combine) the strings into one NSString that will be sent into the next view. You can do this in your PrepareForSegue. Put this in your prepareforsegue but edit the code so it works with your code.
NSString *concatenatedString = [NSString stringWithFormat:#"%# %# %#", textview1.text, textview2.text, textview3.text];
YourViewController *dV = [segue destinationViewController];
dV.stringToStoreValue = concatenatedString;
The first line I concatenate the string
The second line I get the destination view controller from the segue
The third line I set the text to a NSString #property in the destination view controller. You must then in the view did load of the destination view controller set
yourcombinedtextfield.text = stringToStoreValue;
I do not directly set the value of the text field in the prepareForSegue because if the view has not loaded yet then the I would be setting nothing and not see the string on the next page in the textfield!
You're trying to communicate between ViewControllers this answer looks like a good starting point for understanding how this is done..
UPDATE :
newController.textView.text = [NSString stringWithFormat:#"%# %# %#", textView1.text, textView2.text, textView3.text];

Clear a UILabel text and reset it again in xcode?

I have a UILabel set its text.But when I check for some condition and try to
change the text of UILabel if condition not met then Im getting the other other text on already present text of UILabel i.e both texts are overlapping..First I want to clear the present text and reset same UILabel to other text ..How can i do it ?
Im doing this
label.text=#"Welcome";
if(check for some condition)
{
label.text=#"Sorry";
}
But both texts are overlapping on each other...Where Im going wrong?
If you want to clear label first
label.text = #"";
and then give some value to the label
label.text = #"Sorry";
I know it's silly but sometimes it works.
Thanks.
I was having the same problem with Swift 3. It was some intermittent that at times and a text exchange look like a label. I have decided as follows:
self.label.text = "00:00:00"
self.label.setNeedsLayout()
You can try this:
label.text = nil;
And after the condition, you reassign the text.

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

iOS - Navigation Title Not Updating

What I'm doing with this bit of code is grabbing an image sequence, grabbing it's name. Then setting the view's title as the sequences name playing the sequence then setting the title back to the old title.
Problem is the title doesn't seem to be changing on the navigation bar. The NSLogs are outputting the correct values though.
I remember having this issue before and solving it with some "refresh" method.
Here is the pertinent code.
-(void)playSequence
{
if (([animatorViewController isAnimating] == FALSE) && (btnDisable == FALSE))
{
Sequence *tempSequence;
tempSequence = [fullStepList objectAtIndex:lastPlayedSequence];
self.title = [NSString stringWithFormat:#"Assembly - %#", tempSequence.subName];
NSLog(self.title);
[self startAnimator:tempSequence.imageNameScheme forNumFrames:tempSequence.numberOfFrames playInReverse:FALSE];
tempSequence = nil;
tempSequence = [fullStepList objectAtIndex:queuedSequence];
self.title = [NSString stringWithFormat:#"Assembly - %#", tempSequence.subName];
NSLog(self.title);
tempSequence = nil;
}
}
EDIT: This method of changing the title is working else where in this class. The problem seems to come in when trying to set it twice that is causing the issue.
EDIT2: It's actually running both title changes one after another... Fact that it was setting it back to previous was throwing me off.
A navigation item may contains four things: leftBarButtonItem, rightBarButtonItem, title, and titleView. When you need to change the title you should assign your title to navigationItem's title property, not to your view's title property. So it would look like:
self.navigationItem.title = [NSString stringWithFormat:#"Assembly - %#", tempSequence.subName];
self.title points to your viewControllers title which don't shows up in the navigationBar.
The title won't appear to update until after the main run loop executes. Unless -startAnimator:forNumFrames: invokes the main run loop to execute before it returns, you won't see the change.
If you are hosting the UINavigationController inside another view, you need to do this:
self.yourNavigationController.title = #"title";
instead of
self.title = #"blah"
Otherwise you are just changing the title of the view hosting the view navigator. Just a guess.
I recently found myself in a similar situation. My view's title was comprised of a label with an NSMutableAttributedString. Calling [self reloadInputViews] whenever I updated my title worked for me.
The dreaded P.E.B.K.A.C. error was the cause of this confusion. It's actually running both title changes one after another... Fact that it was setting it back to previous was throwing me off.

What is the best way to display long file name in UITablView

I have some source codes to display all file names in a UITablView
I noticed that if the file name too long, for example filenameabcdefghklmn.dat it will display filenameabcde...
I hope to know what is the best way to display long file name in UITablView?
Thanks
interdev
You can set the label properties of the label in which you are entering text like:
[lbl setNumberOfLines:0];
[lbl setLineBreakMode:UILineBreakModeCharacterWrap];
Now this will show the file name in the next line if the file name did not fit in one line.
You need to adjust the label height also.
Hope this helps,
Thanks,
Madhup
Customise your table cell and draw the string directly to the table cell's view.
You can use sizeWithFont:constrainedToSize: to figure out how big your string will be so you can size your cell appropriately.
This post may help you out:
http://www.ubergeek.tv/article.php?pid=143
Allow rotation to landscape mode. Or use a smaller font. Or just let the label get abbreviated with the "..." ellipsis.
There isn't a heck of a lot you can do here.
Show long name in two line in same row...
like
if([myString length] > MAX)
{
myString1 = [myString substringToIndex:MAX];
cell.textLabel.text = myString1;
mystring2 = [myString substringFromIndex:MAX];
cell.detailTextLabel.text = mystring2;
}
You can use
cell.textLabel.numberOfLines=3;
cell.textLabel.lineBreakMode=UILineBreakModeWordWrap;
Put this code in your cellForRowAtIndexPath tableview delegate methods.