iphone - 在 Xcode 中使按钮链接到不同的 ViewController

标签 iphone ios uiscrollview

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

如何链接我循环链接到新 ViewController 的每一张图像

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

enter image description here

最佳答案

为每个按钮添加一个标签。如果使用 for 循环,标签可以是索引计数器 (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
}

关于iphone - 在 Xcode 中使按钮链接到不同的 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12422926/

相关文章:

ios - 应用程序和扩展 - 使用核心数据 == 错误 : sharedApplication()' is unavailable

iphone - 更改 UIImage(不是 UIImageView)的透明度

ios - 在 UiTableView didSelectRowAtIndexPath 更新错误的 Cell

ios - 使用 UIActivityViewController 共享文件 URL 时存在内存泄漏

ios - 检测 UIImagePicker OverlayView 方向

iphone - 如何为地址簿中的联系人创建具有多种类型的 NSMutableDictionary?

ios - 如何将位置分享到 Whatsapp、Facebook 等

ios - 覆盖 setContentOffset

ios - UIScrollView 滚动背景 View

ios - 额外的 20px 顶部插入 UIScrollView 问题