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.
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
精彩评论