2
我已经设置了一个代码,其中Viewcontroller *vc
在Appdelegate.mm
中被全局声明,并且vc被初始化为rootviewcontroller。当我调用Viewcontroller
中的一个方法来更改UILabel时,它在3-4次更改之后开始在先前文本的顶部覆盖。UILabel覆盖以前的值
//AppDelegate.mm
@implementation AppDelegate
ViewController *vc;
- (void)feedSamplesToEngine:(UInt32)audioDataBytesCapacity audioData:(void *)audioData {
if(check>0 || check==-1)
{
[vc writetolabel:check];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
vc = (ViewController *)self.window.rootViewController;
}
..
//ViewcONTROLLER.m
@interface ViewController()
{ AVAudioSession *session;
}
@end
@implementation ViewController
@synthesize appDelegate; //global declaration bitches
- (void)viewDidLoad {
[super viewDidLoad];
appDelegate = (AudioRecorderAppDelegate *)[[UIApplication sharedApplication] delegate];
[email protected]"OTP";
[appDelegate startRecording];
}
- (void)writetolabel:(int) check{
self.TextView.text=nil;
if(check==-1)
self.TextView.text= [NSString stringWithFormat:@"OTP not verified"];
else
self.TextView.text= [NSString stringWithFormat:@"%d", check];
}
- (void)dealloc {
[UITextView release];
[super dealloc];
}
@end
我试图寻找相同的,但没有一个答案解决我的问题。 这些值会定期变化,问题不在于传递的值,而是在前3-4个值之后它们相互重叠。
没有,同样的问题依然存在。 我对这个问题的分析让我觉得每次都会初始化一个新的指向ViewController类的指针(即使它是全局的),然后调用方法。 –
每次为textView赋值时,都会为textView分配一些背景。这样你可以检查你的观点。 – Kumar
新增,self.TextView.backgroundColor = [UIColor whiteColor]; 它的工作原理,谢谢:) 虽然这将是伟大的,如果我知道为什么它发生的确切。 –