iOS,如何查找UITableView的选定行? [英] iOS, How to find selected row Of UITableView?
本文介绍了iOS,如何查找UITableView的选定行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试找到所选的 UITableViewCell
,如下所示:
I'm trying to find selected UITableViewCell
as following:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
if ([indexPath row] == [tableView cellForRowAtIndexPath:indexPath.row]) // i want to place value of selected row to populate the buttons
//([indexPath row] == 0)
//(indexPath.row == ![self cellIsSelected:indexPath])
{
UIButton *AddComment = [UIButton buttonWithType:UIButtonTypeCustom]; // custom means transparent it takes shape same with backgroup image
[AddComment addTarget:self
action:@selector(TestBtns:)
forControlEvents:UIControlEventTouchDown];
// [AddComment setTitle:@"1" forState:UIControlStateNormal];
AddComment.frame = CGRectMake(9.0, 128.0, 96.0, 26.0);
[cell.contentView addSubview:AddComment];
UIImage *buttonAddComment = [UIImage imageNamed:@"addcomment.png"];
[AddComment setBackgroundImage:buttonAddComment forState:UIControlStateNormal];
[cell.contentView addSubview:AddComment];
}
如何实现这一目标,可以吗?引导我,我在做错误的地方。
How to achieve this, can you please guide me, where I'm doing Mistake.
推荐答案
NSIndexPath *selectedIndexPath = [tableView indexPathForSelectedRow];
这篇关于iOS,如何查找UITableView的选定行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文