0

我制作了一个带有 4 个选项卡的选项卡式应用程序。对于第一个选项卡装饰,我使用了苹果网站上的滚动示例。我已经对其进行了编辑,因此它使用了 24 张在页面上垂直滚动的图像。

如何链接我循环的每个图像以链接到新的 ViewController

我已将我的项目上传到http://blakeloizides.co.za/xcode/供您查看和玩弄。

在此处输入图像描述

4

3 回答 3

1

给每个按钮一个标签。如果使用 for 循环,标签可以是 index counter (i) + 1。每个按钮可以有相同的选择器

for (int i =0; i<24; i++) 
{
    //create your button here
    [button setTag:(i+1)];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}

-(IBAction)buttonClicked:(id)sender{
    UIButton *theButton = (UIButton *)sender;
    int tag = theButton.tag;
    //based on tag, do an action here - move to a different viewcontroller
}
于 2012-09-14T12:25:43.647 回答
0

您需要显示UIImageView具有每个独特tag属性的每个图像,并将其UITapGestureRecognizer放在上面。一旦手势将识别水龙头,基于tag属性加载新的Controller.

于 2012-09-14T11:02:59.417 回答
0

在下一个视图中设置 ImageView 和标签,并将所有 imageName 设置为 1.png、2.png.... 并申请循环

for (int i =0; i<24; i++) 
        {
            NSString *imageName=[NSString stringWithFormat:@"%d.png",i];
            UIImageView *imageView= [[UIImageView alloc]initWithImage:[UIImage imageNamed:imageName]];
        }
于 2012-09-14T11:25:16.307 回答