I'm just starting out working on my first iOS app. How do you create a UITableViewCell
that contains a UITextField
that looks like the Title and Location fields when adding an event within the Calendar application? Are there any handy third-party components for doing this?
I can see that the table view has two grouped items and that the text fields have some placeholder text, it's more about how to go about making the text fields take up 100% of their parent table view cells.
Thanks in advance for any help.
You need to add the UITextView as a subview of the UITableViewCell. In the cellForRowAtIndexPath:
method do the following:
Create a UITextView as you normally would:
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,300,40)];
NB: the numbers are the x, y, width, height. Modify these to fit your own app.
Add it as a subview of the cell:
[cell addSubview:textView];
If you only want specific cells to have the textview you will need to do something like
//Use the if statement to specify which row(s) you want the UITextView to appear in
if (indexPath.row == 1) {
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0,0,300,40)];
[cell addSubview:textView];
}
The Table View Programming Guide for iOS has a section called A Closer Look at Table-View Cells. It describes two techniques for customizing a table-view cell: with code and using a pre-built nib. I think it has a lot of information you will be interested in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With