uitextview not displaying text unless clicked on

Discussion in 'iOS Programming' started by Chirone, Feb 1, 2010.

  1. Chirone macrumors 6502

    Mar 2, 2009
    i have a uitextview and i've set the text but it doesn't show up unless i click on the text view to edit it.

    i don't want the text view to be editable and i want the text to just show up...

    this is how i'm making it:

    CGRect frame = CGRectMake(50, 50, 200, 200);
    UITextView *textView = [[UITextView alloc] initWithFrame: frame];
    textView.backgroundColor = [UIColor whiteColor];
    textView.textColor = [UIColor colorWithRed: 0.8 green: 0.8 blue: 0.8 alpha: 1.0];
    textView.font = [UIFont fontWithName:@"Helvetica" size: 17];
    textView.editable = NO;
    textView.text = NSLocalizedString(@"instructions", @"");
    [textView setNeedsDisplay];
    [parentView addSUbview: textView];
    [textView release];
    why does this not work yet you can do textView.text = @"blah" if textview is a uiTextView from an IBOutlet?
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    First, you meant addSubview, right? (Remember, Objective-C is case-sensitive.)

    Second, it works fine for me, but I replaced parentView with self.view, since I'm not sure how you have parentView set up. Perhaps you could elaborate on that as well as where you have included the above code snippet.
  3. Chirone thread starter macrumors 6502

    Mar 2, 2009
    yeah i meant addSubview, i replaced the actual method that i was calling with addSubview
    but that method does the same thing, just calls addSubview

    parentView is the same as self.view in this example, it's just that this method is called with the possibility of parentView being a different view like a scrollview or button

    this method is called inside a loop which creates various other uiView children depending on certain conditions
    the loop is inside another method that gets called from viewDidLoad

    so essentially it's just doing that code in the viewDidLoad method

    it's strange that it only does weird stuff for a uiTextView and nothing else
    but since it doesn't need to be edited i decided i'd get a uiLabel, parent that to a uiScrollView and parent the uiScrollView to the parentView essentially it's the same thing but it works...

    really weird...

Share This Page