我想创建一个buttons.for集群,我正在使用一个这样的循环。
for (int i =0; i< [plistArray count];i++) {
editButton = [[UIButton alloc]initWithFrame:CGRectMake(width-10, -3.6, 39, 35)];
[editButton setImage:[UIImage imageNamed:@"DeleteButton.png"] forState:UIControlStateNormal];
[editButton addTarget:self action:@selector(deleteObjectViewImage:) forControlEvents:UIControlEventTouchUpInside];
}但是当我点击任何随机按钮时,当我点击第一个按钮时(按1,2,3的顺序),分配的函数不是called.It调用的。
发布于 2011-07-02 20:12:57
这里有一个:
#define ButtonHeight 40
#define OffsetBetweenButtons 20
#define ButtonHeightPlusOffsetBetweenButtons (ButtonHeight+OffsetBetweenButtons)
//create 6 buttons from 0,1,2,3,4,5 so totally 6 buttons
for(int buttonIndex=0;buttonIndex<=5;buttonIndex++){
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Button" forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:@"DeleteButton.png"] forState:UIControlStateNormal];
//Set offset in Y axis
button.frame = CGRectMake(20.0, ButtonHeightPlusOffsetBetweenButtons * buttonIndex , 280.0, 40.0);
//Set Tag for future identification
[button setTag:buttonIndex];
[YourView addSubview:button];
}https://stackoverflow.com/questions/6556888
复制相似问题