您可以動態生成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