TableView问题...如何知道行号 [英] The TableView problem...How to know the row number
问题描述
我在做什么
我正在制作一个使用 tableView 的项目.在那个 tableView 中,我的每一行都有一个删除按钮..
I am making a project in which I am using a tableView. In that tableView I have a delete Button in every row..
我想要的
我想要当我按下按钮时...有 1 秒的延迟.之后应该删除该行..在延迟时间内,我按下的行的删除按钮应该隐藏.
I want that When I press the button ...there is a delay of 1 second. and after that the row should be deleted..in that time of delay the delete button of the row that I pressed should be hide.
我的问题
嗯,我可以做这件事,但有一个问题.当我按下任何一行的删除按钮时......只有最后一行的删除按钮隐藏......
Well I am able to do this thing but there is a problem. When I press the delete button of any row ...only the delete button of the last row hides...
问题的根源——依我之见
好吧,我已经在 cellForRowAtIndexPath 中分配了删除按钮..我已经为它分配了方法......当我按下按钮时......该方法被调用......在那个方法中我已经隐藏了删除按钮......
Root of the problem -According to my view
Well I have assigned the delete button in cellForRowAtIndexPath ..
and I have assigned the method for it...when I press the button...The method get called..in that method I have made that delete button hidden...
我的意思是它怎么知道删除按钮应该隐藏在哪一行...
I mean how would it know that In which row that delete button should be hide...
我的问题
当我按下删除按钮时,如何知道应该隐藏在哪一行..现在它每次只在最后一行隐藏..
My Question
When I press the delete button how to know in which row that should hide..Now its hiding every time in the Last row only..
建议...
推荐答案
在你的 tableView:cellForRowAtIndexPath
方法下面使用.
Use below in your tableView:cellForRowAtIndexPath
method.
[myButton addTarget:self
action:@selector(ButtonAction:)
forControlEvents:UIControlEventTouchUpInside];
myButton.tag = indexPath.row ;
实现下面的方法,
-(void) ButtonAction:(id) sender
{
UIButton* myButton = (UIButton*)sender;
myButton.hidden = YES;
//Delete the row at index (myButton.tag)
}
我建议您使用自定义单元格,而不是直接使用 UITableViewCell.
I would suggest you to use custom cell rather then using UITableViewCell directly.
这篇关于TableView问题...如何知道行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!