2017-06-27 85 views
2

我已经设置了一个代码,其中Viewcontroller *vcAppdelegate.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个值之后它们相互重叠。

回答

0

变化,而不是

self.TextView.text = nil 

self.TextView.text=" " 
+1

没有,同样的问题依然存在。 我对这个问题的分析让我觉得每次都会初始化一个新的指向ViewController类的指针(即使它是全局的),然后调用方法。 –

+0

每次为textView赋值时,都会为textView分配一些背景。这样你可以检查你的观点。 – Kumar

+0

新增,self.TextView.backgroundColor = [UIColor whiteColor]; 它的工作原理,谢谢:) 虽然这将是伟大的,如果我知道为什么它发生的确切。 –