您可以在 UIScrollView 中动态生成 UIButtons 并为其分配一个目标以重定向到下一个屏幕。看下面的代码:
- (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;
}
}
-(void)buttonTapped:(id)sender
{
// code for redirecting to another view
// use button tag property for identifying perticular record
}
您可以将文章的标题分配给按钮文本。将文章数据存储在数组中并按以下方式分配。
[button setTitle:(NSString *)[tempArray objectAtIndex:i] forState:(UIControlState)UIControlStateNormal];
希望这会帮助你。