UITextView causing me headaches; Causes app to freeze

Discussion in 'iOS Programming' started by Fontano, Sep 10, 2008.

  1. Fontano macrumors member

    Jun 27, 2008
    I have narrowed down my current issue, to something to do with the UITextView.

    I have a TableView, opening a detail view.
    I have a navigation bar in place.

    The detail view opens fine, and everything is displayed.
    If I click on the navigation bar, to go back to the previous page.

    And the app hangs.
    But doesn't crash out, or cause a fatal issue in the debugger... just freezes.
    (It is not the same result, if say I released an object on the previous page an it is no longer there, this just flat out freezes)

    Can't click on my details in my Cells... can't click on the navigation bar to go to the previous-previous page.

    If I remove the UITextView object from the view/nib file... works fine, no issues. I add it back, but don't connect to anything (just so that it is in the NIB), it causes the issues.

    I have even created a new blank nib, and just added the UITextView... and it causes the issue.

    I am using this UITextView to display multiple lines of text, it won't be editable.

    Any ideas?

    Do I need to implement some of the delegate functions, even though I am not going to be using them?

    The parent page, is a standard ViewController, with a single View
  2. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    Dunno, but you can use UILabel to display multiple lines of text.
  3. Fontano thread starter macrumors member

    Jun 27, 2008
    Thanks for the tip. Does the UILabel have scrolling ability ? I didn't see a setting for that.

    Note: I am downloading the SDK 2.1 update rightnow, so I can't check the UILabel myself at the moment. I am also hoping this will fix the UITextView issue...
  4. Fontano thread starter macrumors member

    Jun 27, 2008
    Okay... the SDK Update didn't fix the issue.

    I have continued to play with it, and I identified another piece to the puzzle.

    I am doing all the work to gather the data (form a webservice), and then opening the new page, from a detached thread:

    The method is getDetails.
    I am allocating and initializing the thread PRIOR to starting the thread.

    [NSThread detachNewThreadSelector:mad:selector(getDetails) toTarget:self withObject:nil];

    If I don't do this as a detached thread... works fine.
    If I remove the UITextView, it works fine (thread or not a thread)
    If I leave the UITextView in (I have now added all the delgates as well), it freezes when launched from a thread, works fine when run in-line (not from the detached thread)
  5. PhoneyDeveloper macrumors 68040


    Sep 2, 2008
    UILabel doesn't scroll.

    In general it's bad to do UI things from secondary threads. Cocoa has some clear statements in the docs about what's thread-safe and what's not. I didn't find the same statements about UIKit.

    If you can, stick to the main thread for UI code. If you need to, use performSelectorOnMainThread from your secondary thread to do things to the UI.

    From your description I would say create the UI on the main thread, do your data gathering/downloading on the background thread. When you have enough data to update the UI use performSelectorOnMainThread to do this.

    Also, NSURLConnection will download data from a web server for you on a secondary thread and call you back on the main thread. If you can use this class you won't have to worry about threads at all.
  6. Fontano thread starter macrumors member

    Jun 27, 2008

    Thank you for the suggestions.... I will work on those in the morning, and try it out. I appreciate the assistance.
  7. Fontano thread starter macrumors member

    Jun 27, 2008
    Well... I couldn't wait till morning.

    I just tried it, and it solved my issues.
    Thank you very much, and I learned something new..

    Thank you again
  8. psantacr macrumors newbie

    Feb 16, 2008
    Let me just tell you...

    This thread saved me a lot of time....


    :apple:COCOA RULES.:apple:

Share This Page