我已经为 textview 创建了一个出口,我试图在一个函数中使用它,在它工作正常的函数之外,在它未声明的内部。当我将它与 StartFunction(textBox) 之类的函数一起传递时,它可以正常工作,但是该函数还必须与许多其他类似的东西一起使用,而且我不喜欢只使用函数传递所有内容的想法。
什么是更好的选择?
// Header File
- (IBAction)startButton_clicked:(id)sender;
@property (strong, nonatomic) IBOutlet UITextView *textBox;
// Main file
- (IBAction)startButton_clicked:(id)sender {
if (currentlyOn == false) StartFunction(headLabel);
else textBox.text = @"Already Started"; // Works fine here
}
void StartFunction(UILabel *_headLabel)
{
_headLabel.text = @"This works fine because it's passed with the function";
textBox.text = @"textBox is undeclared here";
}