开发者

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

I am looking to mimic the following UI using a UITextField within a UITableViewCell (within a UITableView). I am new to MonoTouch and I can't seem to figure out what the code would look li开发者_开发百科ke for this.

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


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

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


The cell is a custom cell. It has some properties, a editable UITextField, and a placehold string for empty content. The following code is writed by hand, so maybe there are some bugs 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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜