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

変数にUIButtons インスタンスが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 に答える