Я добавляю пользовательский вид в главное окно, затем на вид, который создаю кнопку, и кнопка отображается, но действие не выполняется при нажатии кнопки.
нажмите кнопку, чтобы открыть фотогалерею.
и в цикле кнопки создаются.
код, который я использую, есть ...
UIImage *image=[[UIImage alloc] initWithData:data cache:NO];
UIImageView *iv=[[UIImageView alloc] initWithFrame:CGRectMake(200, y, 75, 75)];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(200, y, 75, 75)];
[button setAlpha:0];
[button setTag:i];//change this to your loop counter
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
iv.image=image;
// iv.tag=@"bigimage.jpg";
iv.userInteractionEnabled=YES;
button.userInteractionEnabled = YES;
[iv addSubview:button];
[button release];
y=y+145;
[view1 addSubview:iv];
[iv release];
А также попробуйте этот код, но улучшений нет ...
UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
button.frame=CGRectMake(200, y, 75, 75);
UIImage *img = [[UIImage alloc] initWithData:data];
[button setBackgroundImage:img forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
y = y+145;
[view1 addSubview:button];