开发者

UITextview viewWithTag - updating the text doesn't work while I know I have access to it

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; 
 curre开发者_如何学运维ntPage.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...


-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";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜