我有一个UITableView,它填充了每个单元的信息、详细信息和图像。我也有它,所以当一个单元格被选中时,它会将用户带到一个详细的视图。我想要完成的是如何区分用户单击单元格或单元格中的图像时的区别。
我想要显示一个小的子视图,当用户单击单元格中的图像时,小的子视图将留在原始框架中,但给用户提供其他交互的东西。
我环顾了四周,似乎找不到一个简单的解释或从哪里开始。这是通过facebook和twitter等应用程序完成的,在这些应用程序中,您可以在表格视图中看到用户的个人资料图片,您可以单击该图片,而不是实际的单元格。
任何信息都将是伟大的感谢!
谢谢你@Nekno,我已经开始尝试实现这个方法,如果你不介意澄清或给出你的意见,我有几个问题。
这是我到目前为止所写的
// Here we use the new provided setImageWithURL: method to load the web image with
//SDWebImageManager
[cell.imageView setImageWithURL:[NSURL URLWithString:[(Tweet*)[avatarsURL
objectAtIndex:indexPath.row]avatarURL]]
placeholderImage:[UIImage imageNamed:@"avatar.png"]];
//create the button
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setBackgroundImage:[NSURL URLWithString:[(Tweet*)[avatarsURL
objectAtIndex:indexPath.row]avatarURL]] forState:UIControlStateNormal];
//the button should be as big as the image in tableView
[button setFrame:CGRectMake(10, 10, 45, 45)];
//set the type of action for the button
[button addTarget:self action:@selector(imageSubViewAction:)
forControlEvents:UIControlEventTouchUpInside];
//more stuff
return cell }然后使用我在上面的@selector中指定的操作
-(IBAction)imageSubViewAction:(id)sender{
[UIView beginAnimations:@"animateView" context:nil];
[UIView setAnimationDuration:0.5];
CGRect viewFrame = [subView frame];
viewFrame.origin.x += -300;
subView.frame = viewFrame;
subView.alpha = 1.0;
[self.view addSubview:subView];
[UIView commitAnimations];因此,我知道我必须添加一个动作来解除subView,但首先要做的是。
到目前为止,这似乎对细胞没有任何影响,我不确定下一步我应该采取什么步骤来使其发挥作用。
手势方法是否完全禁用了didselectindexrow的功能?因为我两样都想要。
这种方法似乎只需在单元格中添加一个按钮,并给该按钮一个动作就可以工作,但我有点不知道该从哪里继续我的旅程。
再次感谢,我非常感谢您的帮助!
}发布于 2011-06-07 07:52:55
我认为最简单的方法是添加一个UIButton作为子视图,然后添加您的图像作为UIButton的背景视图,无论是通过界面构建器还是通过创建UIImage。
然后,您可以将事件处理程序连接到Touch up Inside outlet,该插座将处理按钮点击。
使用UIButton时,不应该触发UITableView单元格选择。如果由于某种原因,您发现当用户触摸按钮时表单元格被选中,您可以使用UIImageView而不是UIButton,然后向UIImageView添加一个手势识别器来处理图像上的触摸并取消表单元格选择。
要将手势识别器添加到UIImageView并取消对UITableView的触摸,请执行以下操作:
注意: imageView是一个引用UIImageView的局部变量。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//...
// by default, UITapGestureRecognizer will recognize just a tap.
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];
gestureRecognizer.cancelsTouchesInView = YES; // cancels table view cell selection
[imageView addGestureRecognizer:gestureRecognizer];
[gestureRecognizer release];
//...
}
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
// get the imageView that was tapped
UIImageView* imageView = gestureRecognizer.view;
// do something else
}https://stackoverflow.com/questions/6259260
复制相似问题