嗨,我有一點問題。我的程序不記得通過單擊第一個按鈕生成的隨機值。但我想在另一個按鈕中使用該值,並且存在問題。如果我嘗試返回這個值,程序會說這個方法不應該返回值。這裏是我的代碼看起來像:程序不記得值/不能返回值(XCode)
int randomprocess;
- (IBAction)button:(id)sender {
randomprocess = rand() % 3;
// Do something }
- (IBAction)b1:(id)sender {
if (randomprocess == 0) {
// Do something
} else {
// Do something else
}
如果我不會寫第一行,第二個按鈕將無法識別「randomprocess」。現在,當我宣佈它仍然是零或任何數字,我設置它相等。
你調用'按鈕:'首先,之後'b1:'?在聲明它們時初始化變量也是一件好事。 – Alexander
如果您直接從源代碼複製並粘貼,則當您爲其分配值時,您的錯誤是變量中的拼寫錯誤,randomproces = rand()%3;應該是隨機過程我想象? – Andrei0427
@ Anrei0427不,沒有那個拼寫錯誤就在這裏,我很抱歉。我會在一秒鐘內解決它。 – TomasJ