Black Dot From becomeFirstResponder

Discussion in 'iOS Programming' started by rstafford84, Aug 11, 2009.

  1. rstafford84 macrumors newbie

    Jul 17, 2009
    I'm having trouble figuring out why a black dot appears in the top-left corner of the screen when I call becomeFirstResponder on a textfield. It disappears after the transition animation finishes, but nevertheless I feel like I'm doing something wrong here since none of the apps I use experience this problem.

    Attached Files:

    • dot.png
      File size:
      36.1 KB
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I'm confused about the screenshot you show. I see a table with the first row selected and then at the right side of the screen I see the edge of the keyboard and the black dot you mention. What does the table have to do with your scenario? Why do we only see a bit of the keyboard?
  3. rstafford84 thread starter macrumors newbie

    Jul 17, 2009
    The screenshot is showing my app mid-transition, which is why the keyboard isn't shown fully yet. As soon as the transition finishes, the dot disappears. The screen that I'm transitioning to allows me to edit the data in the cell I just touched.
  4. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I see. You're pushing a new view controller and are pre-loading the keyboard.

    Do you see the dot if you don't pre-load the keyboard?

    Are you creating the view hierarchy for the new view controller in code or IB?

    Are you certain that there's no extra view that might correspond to the black dot lurking somewhere?
  5. rstafford84 thread starter macrumors newbie

    Jul 17, 2009
    Everything is done in code, and although I have a feeling the dot will go away if I did it through IB, I prefer not to. I'm absolutely sure there's no extra code lurking around. The dot does not appear if I disable preloading the keyboard.
  6. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I assume everything is built in your new view controller's loadView. Show that code.

    The other kind of thing to do is comment out the code bit by bit to see what causes the dot to appear and which doesn't. Also building an example app that's based on the same code but simpler will probably also make clear what is the cause.
  7. rstafford84 thread starter macrumors newbie

    Jul 17, 2009
    Sorry, I guess I should probably give a more in-depth explanation. There's nothing special about the two views shown in my pic. They are run-of-the-mill view controllers inheriting from UITableViewController. There's no additional code in loadView. There is a viewDidLoad method, but only to set the buttons on the navigation controller. The first view is your default table in the form of a list. Touching any of the entries will bring you to the second screen, where I have a single cell in grouped mode with a UITextField as a subview. For this screen, upon loading, I bring up the keyboard with the following code:
    - (void)viewWillAppear:(BOOL)animated {
    	[super viewWillAppear:animated];
    	NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    	UITextField *textField = [self textFieldForRowAtIndexPath:indexPath];
    	[textField becomeFirstResponder];
    I have a custom method here that calls up the textfield in the subview, but should not be relevant to the issue at hand. Otherwise, everything else is as standard as it gets. The one thing that I do believe will fix the problem is if I move the code to viewDidLoad instead. However, the keyboard fails to appear at all when I do so.

    PhoneyDeveloper, if you can't identify the problem, might it be possible for you to link to some code performing the same tasks that I'm doing and perhaps I can see if I'm doing anything differently?

    EDIT: Yes, I've tried both commenting out and building a simplified version. Both methods do not work, which leads me to conclude there's some essential part I'm missing out on, possibly the viewDidLoad method I mentioned above.
  8. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    I haven't done what you're trying to do so I don't have any code handy. I do know that this issue comes up on the apple iPhone forum.

    The thing in your description that seems odd to me is that you have a UITableViewController subclass for your second view controller. Why not just have a view with a text field in it? Also, if you change your second view controller to a UIViewController subclass and build the table view yourself in code what happens? UITableViewController does some weird things.
  9. rstafford84 thread starter macrumors newbie

    Jul 17, 2009
    I originally had a UIViewController subclass but switched to UITableViewController because of a different problem I was having. The code I was using to pull up the keyboard didn't seem to want to work in UIViewController unless I put it under -viewDidAppear, which isn't the animation I want.

    EDIT: Got it working! You were right, the problem lies in some obscurity of UITableViewController. It works fine when I subclass UIViewController instead.

Share This Page