用于从数组填充图像的按钮
嘿伙计们,我有一个图像视图,带有弹出控制器。 有一个名为Detailitem 的数组,它将图像加载到图像视图中。 我想要的只是一个将数组中的下一个图像加载到图像视图中的按钮 我该怎么写这个? 这是我的尝试,它不起作用吗?
-(IBAction) nextitem {
NSString * imageName = [NSString stringWithFormat:@"%@.jpg",[detailItem objectAtIndex:+1]];
imageview.image = [UIImage imageNamed:imageName];
}
Hey guys i have an image view, with a popover controller.
There is an array called detailitem which loads images into the image view.
All i want is a button to load next image in array into the image view
how would i write this?
Here is my attempt it doesn't work?
-(IBAction) nextitem {
NSString * imageName = [NSString stringWithFormat:@"%@.jpg",[detailItem objectAtIndex:+1]];
imageview.image = [UIImage imageNamed:imageName];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要跟踪当前开始显示数组中的哪个索引。
将 imageIndex 实例变量添加到您的类中并将其初始化为 0
You need to keep track of which index in the array is currently begin displayed.
Add an imageIndex instance variable to your class and initialize it to 0
什么
你期望做 ?它总是传递 1 并获取数组的第二个元素。如果要循环遍历数组,则需要在某处(例如在属性中)保留索引并递增它。
What do you expect
To do? It will always pass 1 and get the 2nd element of the array. If you want to loop through the array, you need to keep an index somewhere (in a property, for example) and increment it.