moh*_*sha 0 iphone uitableview ios touch-up-inside
我正在创建一个应用程序,我在UITableView的url中显示一些rss内容,直到这里它的工作完美.但在这里我想要的是当用户点击并按住UITableViewCell超过5秒时做其他功能.我只想知道如何知道单个选择并单击并按住UITableViewCell的选择.
谢谢
您必须将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;
}
Run Code Online (Sandbox Code Playgroud)
编辑:
请注意,如果您正在使用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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1493 次 |
| 最近记录: |