嘿,在一件小事上你的帮助。
我有一个带标签的UITextview
// 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];
一段时间后,我想更改上面的“currentPage”文本,并用一些新文本替换它的内容。
-(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";
}
viewWithTag在更改alpha时工作正常,因此我想知道申请文本更新的正确语法......
答案 0 :(得分:3)
-viewWithTag:
方法返回UIView对象,因此要设置特定于UITextview的属性,您应该明确地转换它的类型:
((UITextView*)[self.view viewWithTag:100]).text = @"A new updated text";