Iphone 加载文本时UITextView.text滞后
我想使用UITextView显示文本,UITextView是UITabBarView的一部分,并在以下类中执行此操作: .h-文件:Iphone 加载文本时UITextView.text滞后,iphone,objective-c,ios,xcode,uiviewcontroller,Iphone,Objective C,Ios,Xcode,Uiviewcontroller,我想使用UITextView显示文本,UITextView是UITabBarView的一部分,并在以下类中执行此操作: .h-文件: #import <UIKit/UIKit.h> @interface DescriptionViewController : UIViewController{ IBOutlet UITextView *descriptionText; } @end 当TextView第一次显示为空时,当我切换到另一个选项卡并切换回“TextView-tab”
#import <UIKit/UIKit.h>
@interface DescriptionViewController : UIViewController{
IBOutlet UITextView *descriptionText;
}
@end
当TextView第一次显示为空时,当我切换到另一个选项卡并切换回“TextView-tab”时,它会正确显示。但是很明显,我希望它在第一次被正确显示
我已经尝试将相关代码移动到-viewDidLoad函数,但没有任何更改。此外,我尝试了-setNeedsDisplay函数,但没有成功(可能是我用错了?-[descriptionText setNeedsDisplay]
非常感谢您的帮助,我们将根据您的要求发布更多代码。试试这个
- (void)viewDidLoad
{
[super viewDidLoad];
Globals* myGlobals = [Globals sharedGlobals];
descriptionText.text = [myGlobals.currentLine objectAtIndex:5];
}
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
Globals* myGlobals = [Globals sharedGlobals];
descriptionText.text = [myGlobals.currentLine objectAtIndex:5];
}
请在类的viewWillExample方法上设置断点,然后检查第一次从NSLog(“%@,[myGlobals.currentLine objectAtIndex:5])获得的内容 您缺少[super viewwillbeen:animated];有趣。它在第一次调用时返回(null)。我不知道为什么会发生这种情况。给定的字符串总是以某种方式“滞后”,就像在显示文本后加载一样。
- (void)viewDidLoad
{
[super viewDidLoad];
Globals* myGlobals = [Globals sharedGlobals];
descriptionText.text = [myGlobals.currentLine objectAtIndex:5];
}
-(void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
Globals* myGlobals = [Globals sharedGlobals];
descriptionText.text = [myGlobals.currentLine objectAtIndex:5];
}