I have been playing with UITableView
for some time and upon hitting the keyboard and scrolling issue, I decided to solve it by using the UITableViewController
and take advantage of the automatically scrolling when the keyboard shows up. Unfortunately, this does not occur for me and I can not figure out why, I have tried many things and give up to ask the community.
Here is what I have so far:
- A regular
UIViewController
handling aUIView
(MyView.xib) (this is also the root view) - A regular
UITableViewController
handling aUITableView
in a separateXIB
file (MyTable.xib) - A regular
UITableViewCell
has been dragged into (MyTable.xib) and resides side by side with theUITableView
. ThisUITableViewCell
has no custom class. Also there is an outlet connected toUITableViewController
class. - A regular
UITextField
sits under theUITableViewCell
- I have associated the file's owner identity in MyTable.xib to the
UITableViewController
class - I have connected the delegate and datasource of the
UITableView
to the file's owner
This is how it looks in IB in MyTable.xib
UITableView
UITableViewCell
UITextField
So when I generate my table rows in the UITableViewController, I dequeue the first 5 rows to be regular cells and for the last row I return my outlet "myCell" (UITableViewCell). This is the one that has the UITextField.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
if (indexPath.row == 5) return myCell;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [NSString stringWithFormat:@"Test"];
return cell;
}
Finally, in my ViewController
's viewDidLoad
, I create an instance of the UITableViewController
and display it. It successfully shows the 5 rows and my custom one at the bottom. All in the main view, but ...
- (void)viewDidLoad
{
[super viewDidLoad];
mtc = [[MortgageTableController alloc] initWithNibName:@"MyTable" bundle:nil];
mtc.view.frame = CGRectMake(0, 44, 320, 375);
[self.view addSubview:mtc.view];
}
The problem I'm having is, if I click on the UITextField
, I don't see the table automatically being scrolled in view. I thought this was one of the advantages of using UITableViewController
or I maybe I'm doing something wrong here.
I also tried selecting and/or scrolling the table to the row but with no luck.