I'm currently working on an app where a user has to edit his/her profile. I would like to use the edit mode like in the contacts app. (Labels become Textfields)
Is there an easy way to achieve this? Or do I have to replace the cell.detailTextLabel.text with a uitextfield by myself?
Example contacts app editing view:
http://content.screencast.com/users/EricMulder/folders/Jing/media/0839c0c9-43df-4283-bcf1-65f49b43696f/00000047.png
For anyone interested, here is some sample code to add an UITextField to your cell:
cell.textLabel.text = NSLocalizedString(#"nameLabel", #"");
//add textField
if(![cell viewWithTag:101]) {
UITextField *aliasField = [[UITextField alloc] initWithFrame:CGRectMake(93, 13, 225, 44)];
aliasField.text = #"Eric Mulder";
aliasField.font = [UIFont boldSystemFontOfSize:15.0f];
aliasField.tag = 101;
[cell addSubview:aliasField];
}
cell.detailTextLabel.text = nil;
ejazz,
Why do you suppose that they are labels? ; )
You can draw custom cell with UITextField in interface builder. Load it from xib. And change textfields editable property in your implementation of setEditing:animated: method of your view controller.
Related
I have an app where the users enters information in a few textfields which are then added to a uitextview by a nsstring does anybody know how i can set one of the textfields to italics and keep the others normal
regards
Edit:
Heres my code i want to only change once textfield (e.g textfbookpublisher):
NSString* combinedString = [NSString stringWithFormat:
#"%#,%#.'%#.'%#.%#,%#.",
textfbookpublisher.text,
textfbookauthor.text,
textfbooktitle.text,
textfbookplace.text,
nameofuni.text,
textfbookyear.text];
DissertationGen*bookg = [[DissertationGen alloc] init];
bookg.message = combinedString;
bookg.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:bookg animated:YES]
A quick search would have given you an easy answer. For example, this post.
Simply set the font of the UITextfield you want to a [UIFont italicSystemFontOfSize:].
try this link see accepted answer and also check TTTAttributedLabel library
Bold one Word
now you want only textfbookpublisher in italic then pass it individually to next DissertationGen view
in DissertationGen controller's viewdidload method use following code
UILabel *lblpubl = [[UILabel alloc] init];
lblpubl.font = [UIFont italicSystemFontOfSize:18.0];
lblpubl.text = your variable which contains textfbookpublisher's text;
now use lblpubl as you wish
I have a tabbar application. If there is a badge on a certain tab VoiceOver pronounces N items. I'd like to make it pronounce N messages.
How do I do that?
I had a similar problem,
it seems that UITabBarViewController.tabbar is handling accessibility differently than other views.
So my solution was placing another uiview above the badge as a subview of [tabbar superview] and adding accessibility to this view:
At viewDidLoad:
self.badgeAccessibilityView = [[UIView alloc] init];
//use tabBarView.frame to calculate
self.badgeAccessibilityView.frame = frameAccordingToBadgeLocation;
self.badgeAccessibilityView.userInteractionEnabled = YES;
self.badgeAccessibilityView.isAccessibilityElement = YES;
[self.tabBarView.superview addSubview:self.badgeAccessibilityView];
On badge value change:
self.badgeAccessibilityView.accessibilityLabel =
[NSString stringWithFormat:#"%d Notifications", badgeValue];
In my iphone app, I have created some UITextField in scrollView dynamically. And added one button in xib. On that button's TouchUpInside event, I opened UIImagePickercontroller to open photo library and taking selected image on UIImageView.
Now when modalview is dissmissed, values in my UITextField disappears.
How do I retain the UITextField values?
txt = [[UITextField alloc] initWithFrame:CGRectMake(10.0f, 30.0f, 200.0f, 30.0f)];
[txt addTarget:self action:#selector(keyDown:)forControlEvents:UIControlEventEditingDidEndOnExit];
txt.textColor = [UIColor blackColor];
txt.borderStyle = UITextBorderStyleBezel;
txt.autocorrectionType = UITextAutocorrectionTypeNo;
[fieldArray addObject:txt];
Using for loop I am adding txt to NSMutableArray fieldArray.
Here is the code where I fetch values from TextFields
NSMutableArray *insertValues = [[NSMutableArray alloc]init];
//Taking values from textFields
for (int i=1; i<=nooffields; i++) {
UITextField *tf = (UITextField *)[self.view viewWithTag:i];
NSLog(#"TF : %#",tf.text);
if (tf.text.length<=0) {
tf.text=#"";
}
[insertValues addObject:[NSString stringWithFormat:#"'%#'",tf.text]];
}
EDIT :
And also when I display values from database in this textFields and try to edit it. It gives me null values.
What may be the reason? If there any other alternatives? please help me
UITextField *textField=[[UITextField alloc]init];
[textField setFrame:CGRectMake(x,y, width, hight)];
[textField setBorderStyle:UITextBorderStyleRoundedRect];
[self.view addSubview:textField];
The information that your scrollview uses to get populated should be stored outside the scrollview, in a NSMutableDictionary for example. So everytime cellForRowAtIndexPath gets called it can retrieve the information from that source. So I advise you to store the UITextField's text within the dictionary. You can index it by its tag number. That way you won't loose whatever it contained.
I hope it helps you
Cheers
I finally got a work around for my problem.
I am temporarily storing my textField's values into database when presentModalViewController is called.
These values I retrieve back into the textFields on viewWillAppear.
This may not be a very efficient solution but it worked in my case.
Hope this helps someone.
Thanks for all your responses.
So, I've tried looking all around for information on how to recreate a UILabel (ideally, or a UITextField) with a title (for lack of better work).
Since it's quite hard to explain (half the reason I couldn't find what I was looking for) I've attached an image from the Facebook App.
How would I go about creating labels like this? Either single, or multiple?
Sorry for the simple question, still new to iPhone development.
If you're doing it in a UITableView like the one shown in your capture, you can use the UITableViewCell textLabel property to display a standard left aligned label. Then you only add the UITextField to the cell.
I've done exactly this in an app, it looks good and is pretty simple.
UPDATE:
Something like this (untested, may have some typos):
UITextField *textField = nil;
UITableViewCell *cell = [tableView dequeueCellWithReuseIdentifier: kIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault];
textField = [[UITextField alloc] init];
textField.tag = 12345;
[cell addSubview: textField];
textField.frame = CGRectMake(50, 5, 70, 25);
}
else
{
textField = [cell viewWithTag: 12345];
}
UPDATE2: UITextField wasn't added to UITableCellView.
I have custom UITableViewCells (created in interface builder) which are used for a static UITableView which for the sake of argument I will call the AddUserTableViewController (i.e. I do not use autoreleased cells as I only have 5 rows).
In the top cell (used for the user name) I have embedded a UIButton which I use to open an UIActionSheet which in turn allows an UIImagePicker to set an image on the UIButton (i.e. [button.imageView.image = imageFromImagePicker]). The button has a default image (added in IB) which says "add image".
The image on the button is set without issue and remains in place even when I navigate to the detail page of any of the table cells with the exception of the user name cell which contains the button. When I select this cell the image dissapears and does not reappear once I navigate back to the AddUserTableViewController from the "add name" detail view. The "add image" default image, referred to above, is displayed.
I have tried many strategies amongst which have been:
1) using [self.tableView reloadData], [button.imageView setNeedsDisplay], [self.view setNeedsDisplay] in the viewWillAppear method;
2) using the above methods in the cellForRowAtIndexPath method;
3) using the above methods in the overriden willDisplayCell:forRowAtIndexPath: method;
When I place debugging NSLog statements in the program I can see that the button.imageView.image property is still set to the image selected using the UIImagePicker but it is not displayed (the default image from the nib is displayed).
As I mentioned above, this only happens if I navigate away from the AddUserTableViewController by selecting the UITableViewCell within which the UIButton is embedded.
I am currently at a loss as to what to do and would be extremely grateful for any assistance that anyone could offer. I just need to find a way to update the image on the embedded UIButton in the above-mentioned circumstances.
I've added the a section of the code from the cellForRowAtIndexPath: method just for illustrative purposes -
//populates the personal info section
if (section == kPersonalInfoAddSection) {
//Covers the add image button and the name adding field
if (row == kNameRow) {
UILabel *nameLabel = (UILabel *)[nameCell viewWithTag:kMainTextTag];
UILabel *reqLabel = (UILabel *) [nameCell viewWithTag:kSubTextTag];
//UIButton *imageButton = (UIButton *) [nameCell viewWithTag:kImageTag];
if (mainUser.imagePath != nil) {
UIImage *img = [UIImage imageWithContentsOfFile:mainUserImagePath];
imageButton.imageView.image = img;
[imageButton.imageView setNeedsDisplay];
//[imageButton setNeedsDisplay];
//[nameCell setNeedsDisplay];
NSLog(#"************************** Added the BESPOKE image (%#)to the image button", img);
}
else {
NSLog(#"************************** Added the DEFAULT image (%#)to the image button", addUserImage);
imageButton.imageView.image = addUserImage;
}
UIColor *blackText = [[UIColor alloc] initWithWhite:0 alpha:1];
NSString *firstName;
if (mainUser.firstName){
nameLabel.textColor = blackText;
firstName = mainUser.firstName;
}
else {
nameLabel.textColor = reqLabel.textColor;
firstName = NAME_STRING;
}
NSString *lastName = (mainUser.lastName)? mainUser.lastName : EMPTY_STRING;
NSString *name = [[NSString alloc] initWithFormat:#"%# %#", firstName, lastName];
nameLabel.text = name;
reqLabel.text = REQUIRED_STRING;
[blackText release];
return nameCell;
}
In the cellForRowAtIndexPath are you doing something that would 'unset' the image?