开发者

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

开发者 https://www.devze.com 2023-02-15 05:23 出处:网络
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开发者_开发百

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

精彩评论

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

关注公众号