【发布时间】:2013-12-05 11:33:19
【问题描述】:
我有一个带有自定义单元格的表格视图。在单元格内部有一个水平滚动的滚动视图。在表格视图单元格上添加了一个按钮。但是按钮没有通过触摸响应。按钮没有添加到滚动条上视图。单击此按钮时,我的任务是更改其后面的滚动视图的偏移量,就像下一个按钮一样。如何检测触摸?这是我将内容添加到滚动视图的代码。
for(int i=0;i<[exerciseArrayForeachSection count];i++){
Exercise *data = [exerciseArrayForeachSection objectAtIndex:i];
[_customCell.exTitleLabel setText:data.exName];
if([data.exImage length] < 1){
[[AsyncImageLoader sharedLoader] cancelLoadingURL:_customCell.exThumbImageView.imageURL];
}
else if ([data.exImage length] > 0)
{
int intExerId = [data.exImage intValue];
NSString *fullPathString = [NSString stringWithFormat:@"%@%d/%@",EXER_URL,intExerId,data.exImage];
NSURL* aURL = [NSURL URLWithString:fullPathString];
_customCell.exThumbImageView.imageURL = aURL;
imageUrlDetails=fullPathString;
}
[_customCell.scroll addSubview:_customCell.excerciseDetailsView];
_customCell.scroll.contentOffset=CGPointMake(_customCell.scroll.contentOffset.x+320, _customCell.scroll.contentOffset.y);
}
[_customCell addSubview:_customCell.scroll];
[_customCell.scroll bringSubviewToFront:_customCell.nextBtn];
}
从自定义单元格视图中调用按钮单击的方法,例如:
-(IBAction)nextClickActn:(id)sender{
[[self delegate]nextButtonAction:self];}
在表格视图控制器中,
- (void) nextButtonAction:(id)sender {
UITableViewCell *cell = (UITableViewCell *)sender;
_customCell=(CustomCellFor_Dashboard*)cell;
if ( _customCell.scroll.contentOffset.x <= _customCell.scroll.contentSize.width ) {
CGRect frame;
frame.origin.x = _customCell.scroll.contentOffset.x +_customCell.scroll.frame.size.width;
frame.origin.y = 0;
frame.size = _customCell.scroll.frame.size;
[_customCell.scroll scrollRectToVisible:frame animated:YES];
// pageControlBeingUsed = YES;
}
}
【问题讨论】:
-
你在按钮中添加了目标方法吗?
-
@keyurbhalodiya 编辑了 question.target 方法正在从 tableview 单元类调用,该方法在上面给出
-
[btn addTarget:self action:@selector(nextButtonAction :) forControlEvents:UIControlEventTouchUpInside];
-
问题是 nextButtonAction 被称为从 snother 视图的委托方法。
-
ok 然后设置 if 条件是否从 uitableview 单元格调用。使用 1 个布尔变量。
标签: ios uitableview uiscrollview uibutton