【问题标题】:object cannot be set - either read-only property or no setter found无法设置对象 - 只读属性或未找到设置器
【发布时间】:2010-03-17 18:16:06
【问题描述】:

我在简单地为 UI Button 赋值时遇到了麻烦:

//Assume rect is defined
rect = CGRectMake(13, 10, 48, 48);
profileButton = [[UIButton alloc] initWithFrame:rect];
profileButton.buttonType = UIButtonTypeCustom;

在尝试将 buttonType 分配给 UIButtonTypeCustom 时,我收到“无法设置对象 - 找到只读属性或设置器”。

【问题讨论】:

    标签: iphone objective-c cocoa cocoa-touch iphone-sdk-3.0


    【解决方案1】:

    这是因为buttonType 是只读属性。您只能使用buttonWithType: 创建特定类型的按钮。

    profileButton = [[UIButton buttonWithType: UIButtonTypeCustom] retain];
    profileButton.frame = CGRectMake(13, 10, 48, 48);
    

    (不知道profileButton是什么,但假设它不是保留属性)

    【讨论】:

    • 成功了。初始化时我需要记住这一点。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-25
    • 2014-03-10
    • 2015-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多