views:

18

answers:

1

Hey There, your kind help on a small matter.

I have a UITextview with a tag

// Text view
 UITextView *currentPage = [[UITextView alloc] initWithFrame:CGRectMake(10, 10, 300.0, 194.0)]; 
 currentPage.scrollEnabled = YES; 
 currentPage.textAlignment =  UITextAlignmentLeft;

 currentPage.tag = 100;
 currentPage.editable = NO;
 currentPage.text = @"All is sweet";

 [self.view addSubview:currentPage];
 [currentPage release];

Some time later, I want to change the above "currentPage" text and replace it's content with some new text.

-(void)loadNewPage{
 // works fine, meaning I am "touching" the right object
 [self.view viewWithTag:100].alpha = 0.5f;

 // So why this one isn't legal syntax ?
 //[self.view viewWithTag:100].text = @"A new updated text";

}

The viewWithTag works fine while changing the alpha, Thus I am left wondering about the right syntax to apply for the text update...

+2  A: 

-viewWithTag: method returns UIView object, so to set properties specific to UITextview you should cast its type explicitly:

((UITextView*)[self.view viewWithTag:100]).text = @"A new updated text";
Vladimir
Beautiful! Many thanks Vladimir, highly appreciated.
ShiShi