2010-07-09 42 views
0

簡而言之,我有一個帶有三個按鈕的視圖;iOS4 UIButton選中狀態問題(錯誤:作爲賦值左操作數需要左值)

buttonOne 
buttonTwo 
checkButtonStatus 

if buttonOne is clicked it set its own selected status is yes and buttonTwo selected status to no。 單擊按鈕二相反。

button1和button2默認都沒有被選中。

第三個按鈕(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]; 
    }  
} 

我得到的錯誤是「需要左值作爲轉讓的左操作數」。

我不是程序員,我是一個系統管理員,他被要求做一些原型而無法使其工作。所有幫助非常感謝。

回答

1

當測試相等性是您的-checkButtons方法時,您需要使用'==',而不是單個'='。

+1

你也可以使用'[buttonOne isSelected:NO];'而不是如果你想擺脫等號 – iwasrobbed 2010-07-09 14:48:35

+1

談論一個尷尬的錯誤。非常感謝您的快速響應。將在七分鐘時間內標記爲答案! – 2010-07-09 14:51:56

相關問題