【问题标题】:UITableView row select takes long clickUITableView 行选择需要长按
【发布时间】:2014-01-16 05:25:14
【问题描述】:

我正在使用 UITableView 来显示行数。当我单击该行时,需要长时间单击才能执行操作。我已经检查了这个LINK 它和我的问题一样。但它仍然存在问题。

//表格视图

    bookshelfTbaleView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 250, 150)];
    bookshelfTbaleView.delaysContentTouches=NO;
    [bookshelfTbaleView setAllowsMultipleSelection:YES];
    bookshelfTbaleView.dataSource=self;
    bookshelfTbaleView.delegate=self;
    bookshelfTbaleView.backgroundColor = [UIColor grayColor];
    [bookshelfView addSubview:bookshelfTbaleView];
    [scrollview addSubview:popUpBookShelfView];

//TableView 委托方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0)
    {
        [popUpBookShelfView removeFromSuperview];
        bookShelfClick=0;
    }
    if (indexPath.row==1)
    {
        NSLog(@"%@",string);
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        return 60;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *kCellID = @"cellID";
    UITableViewCell *cell = [bookshelfTbaleView dequeueReusableCellWithIdentifier:kCellID];
    cell.userInteractionEnabled=YES;
    UIFont *myFont = [UIFont fontWithName:@"HelveticaNeue-CondensedBold" size:18];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
        //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    if (tableView==bookshelfTbaleView) {
        if (indexPath.row==0) {
            cell.textLabel.text=@"All Category";
            cell.textLabel.font  = myFont;
            cell.textLabel.textColor=[UIColor whiteColor];
        }
        if (indexPath.row==1) {
            cell.textLabel.text=@"Downloaded Category";
            cell.textLabel.textColor=[UIColor whiteColor];
            cell.textLabel.font  = myFont;
        }

    }
    return cell;
}

当点击 TableView 中的行时,需要长时间点击才能移动到功能

tableView: didSelectRowAtIndexPath:

这是我在表格视图中得到的值。

谁能解决我的问题。

谢谢。

【问题讨论】:

  • 为什么单元格总是为零?
  • 在将文本添加到单元格之前,使其为零
  • 那么您并没有真正重用单元格,而是在每次调用 cellForRow 时创建一个新单元格。
  • 我已经删除了那行代码并检查了,但同样的问题

标签: ios objective-c uitableview


【解决方案1】:

苹果说:

重要提示:您不应在 UIScrollView 对象中嵌入 UIWebView 或 UITableView 对象。如果这样做,可能会导致意外行为,因为这两个对象的触摸事件可能会混淆和错误处理。

因为UITableView 继承自UIScrollView。使用UIView 而不是UIScrollView。

如果你还想在 UIScrollView 中使用 UITableView。

制作一个自定义UIScrollView 并添加它

 - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event  {   

     // If not dragging, send event to next responder
     if (!self.dragging) 
         [self.nextResponder touchesEnded: touches withEvent:event]; 
     else
        [super touchesEnded: touches withEvent: event]; }

然后自定义UITableViewCell

 - (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event  {   
     // If not dragging, send event to next responder
     [super touchesEnded: touches withEvent: event]; }

& 使用这个自定义单元格。

【讨论】:

  • 如果我将 uitableview 添加到 uiview 那么它也会出现同样的问题。需要长按才能转到函数 didSelectRowAtIndexPath。
  • 然后尝试第二种方法回答。
  • 同样的问题。看起来我的代码可能有问题。不知道在哪里..
  • 我认为你在 UITableView 的任何 SuperView 上实现了一些 UITapGestureRecognizer
猜你喜欢
  • 2013-11-27
  • 1970-01-01
  • 2021-07-27
  • 1970-01-01
  • 1970-01-01
  • 2019-09-29
  • 2010-11-13
  • 1970-01-01
  • 2014-09-24
相关资源
最近更新 更多