我已经设置了一个代码,其中Viewcontroller *vc
在Appdelegate.mm
中全局声明,vc初始化为rootviewcontroller。当我从Viewcontroller
调用一个更改UILabel的方法时,它会在3-4个更改之后开始覆盖前一个文本。
//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];
self.TextView.text=@"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个值之后它们会相互重写。
答案 0 :(得分:0)
改为而不是
self.TextView.text = nil
到
self.TextView.text=" "