您可以动态生成UIScrollView中的UIButton并为其指定一个目标以重定向到下一个屏幕。看看下面的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//[myMapView addAnnotation:(id<MKAnnotation>)];
int y=10;
for(int i=0;i<10;i++)
{
CGRect frame = CGRectMake(10, y, 280, 40);
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = frame;
button.tag=i;
[button setTitle:(NSString *)@"new button" forState:(UIControlState)UIControlStateNormal];
[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];
[myScroll addSubview:button];
y+=45;
}
}
- (空)buttonTapped:(ID)发送
{
// code for redirecting to another view
// use button tag property for identifying perticular record
}
可以文章标题分配到按钮上的文字。将文章数据存储在数组中,并按照以下方式进行分配。
[button setTitle:(NSString *)[tempArray objectAtIndex:i] forState:(UIControlState)UIControlStateNormal];
希望这会帮助你。
来源
2013-08-01 12:12:25
hpp
您可以通过集成以下解决方案尝试 http://stackoverflow.com/a/12856174/1228669 http://stackoverflow.com/a/3694455/1228669 基本想法是创建一个具有无限滚动视图按钮并使用计时器滚动它 – prasad
谢谢..这看起来很有趣。不过这是一种解决方法。 – utsavanand