【发布时间】:2014-01-30 23:33:50
【问题描述】:
我的故事板中有一个标签,我正在为viewDidLoad 中的标签设置文本,但是当我调用我的方法时,标签没有更新。当我的滚动视图滚动时,我正在调用我的方法 1。
这是我的代码示例;
//.h
NSString *text;
//.m
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
[self method1];
}
-(void) method1{
text = @"Here is the text";
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
NSTimer *timer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
[runloop addTimer:timer forMode:NSRunLoopCommonModes];
[runloop addTimer:timer forMode:UITrackingRunLoopMode];
}
-(void) updateLabel{
label.text = text;
}
我应该如何更新我的标签?谢谢。
【问题讨论】:
-
您是否将标签连接到视图控制器中的
IBOutlet? -
你执行过
updateLabel方法吗? -
is text an ivar.... 我在 -(void) changeDiscount:(int)currentPagePresentation{ 和
label.text = text中看到了这个text = @"a";;用不同的方法 -
设置断点并确保文本在进入该方法时确实是
a。当然要确保它不为空 -
@user3255346 将设置它,但您仍然需要在 Interface Builder 中连接它
标签: ios objective-c uilabel