我正在创建一个应用程序,在那里我显示了一些rss内容从url为我的UITableView,直到这里,它的工作完美。但在这里,我想要的是,当用户单击并在UITableViewCell上停留超过5秒时,可以执行其他功能。我只想知道一个单一的选择,点击和保持选择的UITableViewCell。
谢谢
发布于 2013-01-02 05:07:57
您必须向单元格中添加一个UILongPressGestureReconizer,并将其设置为minimumPressDuration
为5。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 5.0;
[cell addGestureRecognizer:longPress];
}
// Do additional setup
return cell;
}
编辑:
请注意,如果使用的是prototypeCells
,则!cell
条件永远不会为真,因此您必须编写如下所示的内容:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
if (cell.gestureRecognizers.count == 0) {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 5.0;
[cell addGestureRecognizer:longPress];
}
return cell;
}
https://stackoverflow.com/questions/14122598
复制相似问题