0

我不明白为什么我会收到“[UIScrollView imageView]:无法识别的选择器发送到实例”

    for (int i=0;i<[imagesForGame count];i++)
        {      
            UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            button.frame = CGRectMake(i*310, 0, 310, 200);
            [button setImageWithURL:[NSURL URLWithString:[imagesForGame objectAtIndex:i]] forState:UIControlStateNormal];
            [button addTarget:self action:@selector(openFullPic:) forControlEvents:UIControlEventTouchUpInside];
            [_myScroller addSubview:button];
        }


    -(void)openFullPic:(UIButton *)sender
    {

        UIButton *random = (UIButton *)[_myScroller viewWithTag:sender.tag];
        UIImageView *test = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
        test.image = random.imageView.image; // <-- Error
        ...
    }
4

3 回答 3

1

因为您从未为按钮设置标签。在第一个循环中做,button.tag = i;

于 2013-09-30T08:45:52.320 回答
1

UIButton在变量中有 s 实例,sender因此您根本不需要使用viewWithTag;-)

于 2013-09-30T08:47:21.187 回答
1

无论如何,发件人将是一个按钮,因此请改用它。

-(void)openFullPic:(UIButton *)sender
{

    UIButton *random = (UIButton *)sender;
    UIImageView *test = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
    test.image = random.imageView.image; // <-- No more error.
    ...
}
于 2013-09-30T08:47:42.177 回答