How to achieve a similar interface with a UITextField inside a UITableView (UITableViewCell)?

I want to emulate the following user interface using a UITextField in a UITableViewCell (in a UITableView). I'm new to MonoTouch, and I can't figure out what the code for this looks like.

enter image description here

+3
source share
2 answers

It is very simple. Just add a UITextField with no background color to the cell. Add the code below to your method cellForRowAtIndexPath.

UITextField *inputText = [[UITextField alloc]initWithFrame:CGRectMake(10,10,280,22)];
inputText.textAlignment = UITextAlignmentLeft;
inputText.backgroundColor = [UIColor clearColor];
inputText.placeHolder = @"Street";
[cell.contentView addSubview:inputText];
[inputText release];
+4
source

A cell is a user cell. It has some properties, an editable UITextField, and a place bar for empty content. The following code is called manually, so there may be some errors inside.

@interface EditableCell : UITableViewCell {
   UITextField *mTextField;
}
@property UITextField *textField;

- (void)setPlaceHoldString:(NSString *)placeHolder;
@end

@implement EditableCell
@synthesize textField = mTextField;

- (void)setPlaceHoldString:(NSString *)placeHolder
{
   self.textField.placeHolder = placeHolder;
}

- (UITextField *)textField
{
  if (mTextField == nil) {
      mTextField = [[UITextField alloc] init];

      // Configure this text field.
      ...

      [self addSubView:mTextField];
  }

   return mTextField;
}

- (void)dealloc
{
  self.textField = nil;
  [super dealloc];
}
@end
+1
source

All Articles