【问题标题】:IOS4 UIButton Selected State Question (Error: Lvalue required as left operand of assignment)IOS4 UIButton Selected State Question (Error: Lvalue required as left operand of assignment)
【发布时间】:2010-07-09 14:44:06
【问题描述】:

简单来说,我有一个包含三个按钮的视图;

buttonOne
buttonTwo
checkButtonStatus

如果 buttonOne 被点击,它会将自己的选中状态设置为 yes 并将 buttonTwo 的选中状态设置为 no。 单击 buttonTwo 则相反。

buttonOne 和 buttonTwo 默认都是不选中的。

第三个按钮 (checkButtonStatus) 应该执行检查以确保至少其他两个按钮中的一个已被点击。

我有下面详细的代码:

- (IBAction)setButtonOne:(id)sender {
    buttonOne.selected = YES;
    buttonTwo.selected = NO;
}

- (IBAction)setButtonTwo:(id)sender {
    buttonOne.selected = NO;
    buttonTwo.selected = YES;
}

- (IBAction)checkButtons:(id)sender {
    if (buttonOne.selected = NO || buttonTwo.selected = NO) {
    UIAlertView *callAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"You have not selected a button"
       delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [callAlert show];
    [callAlert release];
    }    
}

我得到的错误是“需要左值作为赋值的左操作数”。

我不是程序员,我是系统管理员,被要求制作原型但无法使其正常工作。非常感谢所有帮助。

【问题讨论】:

    标签: iphone objective-c ios4


    【解决方案1】:

    当测试相等性是您的 -checkButtons 方法时,您需要使用“==”,而不是单个“=”。

    【讨论】:

    • 如果你想去掉等号,你也可以使用[buttonOne isSelected:NO];
    • 说说一个尴尬的错误。非常感谢您的快速回复。将在 7 分钟内标记为答案!
    猜你喜欢
    • 2021-06-07
    • 1970-01-01
    • 2015-07-11
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-09
    • 1970-01-01
    相关资源
    最近更新 更多