iphone - 从另一个类更改 UILabel 的文本

标签 iphone objective-c ios uiviewcontroller uilabel

我有一个 View Controller 和一个类(我正在使用 Storyboard)。如何从类中更改 UILabel(在 View Controller 中)的文本?我试过这个,但无济于事:

ViewController *mainView = [[ViewController alloc] init];
[mainView view];

[mainView.progressBar setProgress:integer animated:YES];

NSLog(@"Updated Progress Bar");

NSString *progressLabelText = [NSString stringWithFormat:@"%@ out of %i followers", userString, [self.followers count]];

[mainView.progressLabel setText:progressLabelText];

NSLog(@"Updated Progress Label Text: %@", progressLabelText);

使用此代码不会更改文本。我应该怎么做?

编辑:ViewController 的 .h 文件中的进度条和标签如下所示:

@property (nonatomic, strong) IBOutlet UIProgressView *progressBar;
@property (nonatomic, strong) IBOutlet UILabel *progressLabel;

并且它们在 Interface Builder 中完全链接在一起。

最佳答案

使用 delegateclassesviewcontrollers 之间进行messaging

引用The Basics of Protocols and Delegates链接。

关于iphone - 从另一个类更改 UILabel 的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14196708/

相关文章:

ios - 如何获取UIScrollView的zoomScale和contentOffset,并应用于更大的图像?

iphone - cocos2d 流行场景事件

ios - 如何用播放 MPMoviePlayerController 的 UIProgressView 替换 UISlider?

iphone - 一次仅允许有一个 UITableViewCell 附件复选标记

ios - 为什么 `transform.rotation` 可用于 CoreAnimation,但无法使用 getter 访问?

ios - React Native 中的背景 gps 位置

ios - 在 Swift 3 和 Xcode 8 中使用加速度计和校准

ios - 在 SWIFT 中创建具有动态值/键的可变字典

iphone - 在iOS上后台录音

objective-c - 帮助解决编译器警告 : Initialization from distinct Objective-C type when types match