i am using a UITextView inside a tableView cell in order edit text.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITextField *textName = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 270, 24)];
[cell addSubview:textName];
[textName release];
}
This works, but when running it on the iPad it isn't correct.
I've tried to determine the width of cell using cell.contentView.frame.size.width
but this always returns 320.0 for both iPhone and iPad
Also on the iPad when in landscape mode shouldn't the width of cell be bigger?
Teo
Ideally you'd create a custom UITableViewCell
and adjust your control sizes/positions in layoutSubviews
.
If you're going to add the control in tableView:cellForRowAtIndexPath:
, then you can get the width from the tableView itself:
UITextField *textName = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width-50, 24)];
textName.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
.[cell.contentView addSubview:textName]
). The content view automatically shrinks to handle editing mode, among other things.Subclassing UITableViewCell is a bit overkill if you just want to tweak layout — it's my impression that auto-resizing is faster than manual sizing using layoutSubviews.
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