我有一个UITableView,并为每个单元填充信息,详细信息和图像。我也有它,所以当一个单元格被选中时,它将带给用户一个详细的视图。我试图完成的是如何区分用户单击单元格或单元格中的图像时的差异。在UITableView中选定的UIImage
我想显示一个小的子视图,当用户单击单元格中的图像时,小的子视图将保留在原始框架中,但会给用户其他可与其交互的东西。
我看了四周,似乎甚至找不到一个简单的解释或某处开始。它是由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 }
然后我用这个动作,我在@选择指定的上述
-(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的功能?因为我想有两个。
看起来好像这种方法只需在单元格内添加一个按钮,然后给该按钮一个动作就可以工作,但我有点失落,无法继续我的旅程。
再次感谢我非常感谢帮助!
}
现在看到您的代码,我看到您正在使用内置的UITableViewCell.imageView。我以为你有一个自定义的单元格。在你的情况下,我只是让你的UIButton的backgroundColor设置为'[UIColor clearColor]'而不是背景图像。我认为你只需要将你的按钮作为子视图添加到单元格中,例如'[cell addSubview:button]'和[cell bringSubviewToFront:button]'。这样,图片的延迟加载和清晰的按钮就位于顶部。 – nekno 2011-06-07 01:17:24
谢谢,我感谢您的洞察力!我正在处理其余的部分。只需在单元格中添加按钮是有意义的。我已经有了一个动画和子视图,我只需要将它实现到单元格中......我肯定会更新这篇文章,当我确定将来为任何其他人试图实现这一目标时会更新这篇文章。非常感谢! – FreeAppl3 2011-06-07 01:59:33
嗯,我得到它的工作......难的部分!现在我似乎无法摆脱那个麻烦的按钮...我已经尝试了一切,甚至采取了放置在一个图像,所以我打开Photoshop的空白image.png并把它放在.....猜猜还是白色白色的蓝色选择... [按钮setBackgroundImage:[UIImage imageNamed:@“noimage.png”] forState:UIControlStateNormal]; [button setBackgroundColor:[UIColor clearColor]];这些工作都没有,我尝试了其他几种方法来尝试......当像这样简单的事情成为问题时,我会笑起来 – FreeAppl3 2011-06-07 03:29:55