Fantattitude
Fantattitude

Reputation: 1842

How to make a UITextView not take the focus when initializing?

I'm using code to create a detailed view pushed when you press a row of an UITableView, but theres a problem.

The detailed view contain an UITextView and when a detailedView is called (only first time) this make the UITableView row pressed to lose its pressed state. It shouldn't ! It should lose the pressed state only when returning from the detailed view to the list view.

As soon as I remove the UITextView from my code, no problem !

I think it's something like UITextView taking focus?

Is there any way to avoid this ? By subclassing or such?

Upvotes: 0

Views: 457

Answers (1)

jstevenco
jstevenco

Reputation: 2953

Hmmm not seeing this in the sandbox I just wrote.

  • Created a simple navigation-based project.
  • Added a view controller to the project with XIB; added a UITextField to the XIB.
  • Made following code changes to the root view controller:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 1;
    }
    

    in cellForRowAtIndexPath:

    cell.text = @"Push me";
    

    in didSelectRowAtIndexPath:

    SimpleViewController *detailViewController = [[SimpleViewController alloc] initWithNibName:@"SimpleView" bundle:nil];
    

    in viewDidLoad:

    self.navigationItem.title = @"Home";
    

  • Selecting the "Push me" row highlights the row and pushes the SimpleViewController onto the stack. Selecting the "Home" back button pops the view off the stack, returning to the table view and deselecting/un-highlighting the selected row. This is true whether or not the textfield in the SimpleViewController is the first responder at the time of the back navigation.

    Upvotes: 1

  • Related Questions