Scrollviewcustomcontrol未发送正确的ID以显示所需的输出。我们有两个textview显示了scrollview中的4篇文章片段。它们是scrollview的子视图。现在点击它们,我希望打开该文章的详细信息页面以及滚动条,以便可以以完整形式浏览/滚动所有新闻。 ScrollerView就位,使用分页,并从头开始显示所有记录。它只是没有找到我们点击的确切文章。 我试图通过分配给它的textviews和按钮传递值。但是它可以传递两个值,因为我们有两个文本视图......并且有四篇文章。文章编号3传递文章编号1的ID。文章编号4传递文章编号2的ID。 有什么想法吗?
- (IBAction) tappedItemAtIndex:(id)sender {
UIButton *tappedButton = (UIButton*) sender;
NSInteger selectedIndex = [tappedButton tag];
}
int j=0;
for (int i = 0; i < rowOne.count; i++) {
if (j==1) {
j++;
}
count =i+1;
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView*subView=[[UIView alloc ]initWithFrame:frame];
[self.scrollView addSubview:subView];
CGRect myframe=CGRectMake(107, 46, 258, 128);
//CGRect myframe=CGRectMake(13, 46, 352, 128);
Book*book=[rowOne objectAtIndex:i];
UIButton*backViewButton=[UIButton buttonWithType:UIButtonTypeCustom];
backViewButton.frame=CGRectMake(107, 46, 258, 128);
[backViewButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
buttontitle=book.title;
[backViewButton addTarget:self action:@selector(tappedItemAtIndex:)forControlEvents:UIControlEventTouchUpInside];
[backViewButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[backViewButton setTitle:buttontitle forState:UIControlStateNormal];
[subView addSubview:backViewButton];
backViewButton.tag=j;
j++;
Book*book1=[rowOneSecond objectAtIndex:i];
UIButton*backViewButton1=[UIButton buttonWithType:UIButtonTypeCustom];
backViewButton1.frame=CGRectMake(531, 99, 300, 100);
[backViewButton1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
NSString*title=book1.title;
backViewButton1.tag=j;
[backViewButton1 addTarget:self action:@selector(tappedItemAtIndex:)forControlEvents:UIControlEventTouchUpInside];
[backViewButton1 setTitle:title forState:UIControlStateNormal];
[subView addSubview:backViewButton1];
}
答案 0 :(得分:1)
您是否尝试将标签设置为textViews。就像在scrollview中添加它们一样,我假设你运行一个循环,所以将textView添加到一个按钮,然后将该按钮添加到scrollview并指定tag = index(循环增量变量)。将目标添加到按钮。从那里你可以得到按钮的标签,然后通过创建委托协议将它传递给超类。
<强>更新强>
//我假设你有这种类型的功能绑定到每个按钮的touchUpInside。
- (IBAction) tappedItemAtIndex:(id)sender {
UIButton *tappedButton = (UIButton*) sender;
NSInteger selectedIndex = [tappedButton tag];
}
答案 1 :(得分:1)
要滚动到基于页面的内容,请在滚动条视图中存储pageNumber。当您按“下一页”按钮或以某种方式滚动到下一页时,增加页码,然后每次加载页面呼叫时:
- (void)loadPage:(NSInteger)pageNumber
{
// textViews is an NSArray of the 2 textviews you have in your scroller view
// articles is an NSArray in scrollerview containing all articles as strings
unsigned int i, article;
for(i = 0; i < [textViews count]; ++i)
{
article = pageNumber*[textViews count]+i;
if(article < [articles count])
{
[(UITextView *)[textViews objectAtIndex:i]
setText:[articles objectAtIndex:article]];
} else {
[(UITextView *)[textViews objectAtIndex:i]
setText:@""]; // blank pages, because we're at the end
}
}
}
答案 2 :(得分:0)
UIScrollView contentOffSet属性,
CGPointMake这是你需要跳跃的确切点
scrollView.contentOffSet = CGPointMake();
对你有帮助,我早点实施了..