tag:blogger.com,1999:blog-865923359735383241.post4851749910747131404..comments2023-10-29T07:27:09.012-06:00Comments on Ccna final exam - java, php, javascript, ios, cshap all in one: Having a UITextField in a UITableViewCellUnknownnoreply@blogger.comBlogger9125tag:blogger.com,1999:blog-865923359735383241.post-91558665896867662262012-06-08T19:10:01.208-06:002012-06-08T19:10:01.208-06:00I said had it working. =) Anyway I used the Editab...I said had it working. =) Anyway I used the EditableDetailView sample. I think the EditCell class might be the key. Did you try that sample?Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-50947959048914310752012-06-08T19:09:55.734-06:002012-06-08T19:09:55.734-06:00I ran into the same problem. It seems that setting...I ran into the same problem. It seems that setting the cell.textlabel.text property brings the UILabel to the front of the contentView of the cell.<br />Add the textView after setting textLabel.text or (if that's not possible) call: [cell.contentView bringSubviewToFront:textField].Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-62923227922555025562012-06-08T19:09:52.451-06:002012-06-08T19:09:52.451-06:00I realy struggled with this task on the iPad, with...I realy struggled with this task on the iPad, with text fields showing up invisible in the UITableView, and the whole row turning blue when it gets focus.<br /><br />What worked for me in the end was the technique described under "The Technique for Static Row Content" in Apple's<br />Table View Programming Guide. I put both the label and the textField in a Table View Cell in the NIB for the view, and pull that cell out via an outlet in cellForRowAtIndexPath. The resulting code is much neater than UICatalog.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-17438029123427939282012-06-08T19:09:50.237-06:002012-06-08T19:09:50.237-06:00This a complex problem. I did post my solution in ...This a complex problem. I did post my solution in a similar post: http://stackoverflow.com/questions/350868/clicking-on-uitextfield-in-a-uitableviewcell/2030005#2030005Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-50584173128220100282012-06-08T19:09:45.743-06:002012-06-08T19:09:45.743-06:00I had been avoiding this by calling a method to ru...I had been avoiding this by calling a method to run [cell.contentView bringSubviewToFront:textField] every time my cells appeared, but then I discovered this relatively simple technique:<br /><br />cell.accessoryView = textField;<br /><br /><br />Doesn't seem to have the same background-overpasting issue, and it aligns itself on its own (somewhat). Also, the textLabel auto-truncates to avoid overflowing into (or under) it, which is handy.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-6927522037677899872012-06-08T19:09:38.500-06:002012-06-08T19:09:38.500-06:00This should not be difficult. When creating a cell...This should not be difficult. When creating a cell for your table, add a UITextField object to the cell's content view<br /><br />UITextField *txtField = [[UITextField alloc] initWithFrame....]<br />...<br />[cell.contentView addSubview:txtField]<br /><br /><br />Set the delegate of the UITextField as self (ie your viewcontroller) Give a tag to the text field so you can identify which textfield was edited in your delegate methods. The keyboard should pop up when the user taps the text field. I got it working like this. Hope it helps.Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-15326571532003397692012-06-08T19:09:36.481-06:002012-06-08T19:09:36.481-06:00Try this one. It can handle scrolling as well and ...Try this one. It can handle scrolling as well and you can reuse the cells without the hassle of removing subviews you added before.<br /><br />- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{<br /> return 10;<br />} <br /><br />- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {<br /> UITableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"Cell"];<br /> if( cell == nil)<br /> cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease]; <br /><br /> cell.textLabel.text = [[NSArray arrayWithObjects:@"First",@"Second",@"Third",@"Forth",@"Fifth",@"Sixth",@"Seventh",@"Eighth",@"Nineth",@"Tenth",nil] <br /> objectAtIndex:indexPath.row];<br /><br /> if (indexPath.row % 2) {<br /> UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 21)];<br /> textField.placeholder = @"Enter Text";<br /> textField.text = [inputTexts objectAtIndex:indexPath.row/2];<br /> textField.tag = indexPath.row/2;<br /> textField.delegate = self;<br /> cell.accessoryView = textField;<br /> [textField release];<br /> } else<br /> cell.accessoryView = nil;<br /><br /> cell.selectionStyle = UITableViewCellSelectionStyleNone;<br /> return cell; <br />}<br /><br />- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {<br /> [inputTexts replaceObjectAtIndex:textField.tag withObject:textField.text];<br /> return YES;<br />}<br /><br />- (void)viewDidLoad {<br /> inputTexts = [[NSMutableArray alloc] initWithObjects:@"",@"",@"",@"",@"",nil];<br /> [super viewDidLoad];<br />}Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-44096628690496004822012-06-08T19:09:35.570-06:002012-06-08T19:09:35.570-06:00Here is how I have achieved this:
TextFormCell.h
...Here is how I have achieved this:<br /><br />TextFormCell.h<br /><br />#import <UIKit/UIKit.h><br /><br />#define CellTextFieldWidth 90.0<br />#define MarginBetweenControls 20.0<br /><br />@interface TextFormCell : UITableViewCell {<br /> UITextField *textField;<br />}<br /><br />@property (nonatomic, retain) UITextField *textField;<br /><br />@end<br /><br /><br />TextFormCell.m<br /><br />#import "TextFormCell.h"<br /><br />@implementation TextFormCell<br /><br />@synthesize textField;<br /><br />- (id)initWithReuseIdentifier:(NSString *)reuseIdentifier {<br /> if (self = [super initWithReuseIdentifier:reuseIdentifier]) {<br /> // Adding the text field<br /> textField = [[UITextField alloc] initWithFrame:CGRectZero];<br /> textField.clearsOnBeginEditing = NO;<br /> textField.textAlignment = UITextAlignmentRight;<br /> textField.returnKeyType = UIReturnKeyDone;<br /> [self.contentView addSubview:textField];<br /> }<br /> return self;<br />}<br /><br />- (void)dealloc {<br /> [textField release];<br /> [super dealloc];<br />}<br /><br />#pragma mark -<br />#pragma mark Laying out subviews<br /><br />- (void)layoutSubviews {<br /> CGRect rect = CGRectMake(self.contentView.bounds.size.width - 5.0, <br /> 12.0, <br /> -CellTextFieldWidth, <br /> 25.0);<br /> [textField setFrame:rect];<br /> CGRect rect2 = CGRectMake(MarginBetweenControls,<br /> 12.0,<br /> self.contentView.bounds.size.width - CellTextFieldWidth - MarginBetweenControls,<br /> 25.0);<br /> UILabel *theTextLabel = (UILabel *)[self textLabel];<br /> [theTextLabel setFrame:rect2];<br />}<br /><br /><br />It may seems a bit verbose, but it works!<br /><br />Don't forget to set the delegate!Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.comtag:blogger.com,1999:blog-865923359735383241.post-54968996716515925852012-06-08T19:09:31.524-06:002012-06-08T19:09:31.524-06:00Try this out. Works like a charm for me (on iPhone...Try this out. Works like a charm for me (on iPhone devices). I used this code for a login screen once. I configured the table view to have two sections. You can of course get rid of the section conditionals.<br /><br />- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {<br /><br />UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:kCellIdentifier];<br />if (cell == nil) {<br /> cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault <br /> reuseIdentifier:kCellIdentifier] autorelease];<br /> cell.accessoryType = UITableViewCellAccessoryNone;<br /><br /> if ([indexPath section] == 0) {<br /> UITextField *playerTextField = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];<br /> playerTextField.adjustsFontSizeToFitWidth = YES;<br /> playerTextField.textColor = [UIColor blackColor];<br /> if ([indexPath row] == 0) {<br /> playerTextField.placeholder = @"example@gmail.com";<br /> playerTextField.keyboardType = UIKeyboardTypeEmailAddress;<br /> playerTextField.returnKeyType = UIReturnKeyNext;<br /> }<br /> else {<br /> playerTextField.placeholder = @"Required";<br /> playerTextField.keyboardType = UIKeyboardTypeDefault;<br /> playerTextField.returnKeyType = UIReturnKeyDone;<br /> playerTextField.secureTextEntry = YES;<br /> } <br /> playerTextField.backgroundColor = [UIColor whiteColor];<br /> playerTextField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support<br /> playerTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support<br /> playerTextField.textAlignment = UITextAlignmentLeft;<br /> playerTextField.tag = 0;<br /> //playerTextField.delegate = self;<br /><br /> playerTextField.clearButtonMode = UITextFieldViewModeNever; // no clear 'x' button to the right<br /> [playerTextField setEnabled: YES];<br /><br /> [cell addSubview:playerTextField];<br /><br /> [playerTextField release];<br /> }<br />}<br />if ([indexPath section] == 0) { // Email & Password Section<br /> if ([indexPath row] == 0) { // Email<br /> cell.textLabel.text = @"Email";<br /> }<br /> else {<br /> cell.textLabel.text = @"Password";<br /> }<br />}<br />else { // Login button section<br /> cell.textLabel.text = @"Log in";<br />}<br />return cell; <br />}<br /><br /><br />Result looks like this:Userhttps://www.blogger.com/profile/11557173689529910046noreply@blogger.com