Objective c 无法将值分配给只读属性UIButton

Objective c 无法将值分配给只读属性UIButton,objective-c,Objective C,我刚开始用Objective C开发ios。我正在尝试开发一个简单的应用程序,它有一个标签和一个按钮。单击按钮时,标签内容和按钮标题应该会更改。然而,当我试图更改ui按钮的标题时,我得到了错误 Error :Assignment to readonly property 这是我的基本代码 ViewController.h @interface ViewController : UIViewController @property(nonatomic , weak) IBOutlet UILab

我刚开始用Objective C开发ios。我正在尝试开发一个简单的应用程序,它有一个标签和一个按钮。单击按钮时,标签内容和按钮标题应该会更改。然而,当我试图更改
ui按钮的标题时,我得到了错误

Error :Assignment to readonly property
这是我的基本代码

ViewController.h

@interface ViewController : UIViewController
@property(nonatomic , weak) IBOutlet UILabel* labelName;
@property(nonatomic , weak) IBOutlet UIButton* greetButton;

-(IBAction)greetClickedAction:(id)sender; //Button connected here to get the click event
@end
ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

-(IBAction)greetClickedAction:(id)sender
{
    _labelName.text  = @"Label Changed";    //This Works fine
    greetButton.currentTitle=@"New Title";  //Error :Assignment to readonly property
}

@end
我的问题是,为什么在将某些内容分配给UIButton而不是UILabel时会出现错误?我怎样才能解决这个问题

更新:

按照@dasblinkenlight的建议,我可以通过执行以下操作来删除readonly错误,但代码仍然不会更改按钮的标题

_greetButton.titleLabel.text = @"New Title";

greetButton.currentTitle
用于检查按钮上的文本。它不能直接设置,因为它是计算出来的。您可以设置的文本属性,或者调用
setTitle:forState:

[_greetButton setTitle: @"New Title" forState: UIControlStateNormal];

请尝试以下操作一次:

[_greetButton setTitle:@"New title" forState:UIControlStateNormal];

是的,删除了只读错误(也作为一种更正,假设它是“greetButton”,因为我没有进行语法化),但是标题没有改变按钮的文本按钮的标题仍然没有改变