我試圖做出一個操作,每次按下按鈕時,都會向視圖添加一個按鈕。我沒有嘗試過的作品。從IBAction以編程方式添加UIButton
如果有人能夠清理該做什麼,這將是非常感謝。
這是在我的按鈕添加按鈕的最近一次嘗試:
-(IBAction) addButton{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(10,10,50,50);
button.tag = 1;
[button addTarget:self
action:@selector(buttonTouched:)
forControlEvents:UIControlEventTouchUpInside];
[view addSubview:button];
}
您確定調用該方法嗎? – Alexander 2012-03-29 04:53:39
檢查IBAction是否正確接線。有時趕時間,我們錯過了綁定動作/ iboutlets ... – 2012-03-29 04:56:10
還要確保'view'不是'nil'。 – Costique 2012-03-29 05:04:24