【问题标题】:UIButton in UITableViewCell events not workingUITableViewCell 事件中的 UIButton 不起作用
【发布时间】:2011-01-08 18:28:28
【问题描述】:

我在网上看到了这个问题,但列出的解决方案都不适合我!

我已将 UIButton 添加到 IB 中的 UITableViewCell。我已经为 UITableViewCell 分配了一个自定义 UITableViewCell 类。我的自定义 UITableViewCell 类有一个 IBAction,它连接到 Touch Up Inside 事件(我尝试过其他事件,它们都不起作用),但从未调用 IBAction 函数!

UITableViewCell 中没有其他内容,我已将 UIButton 直接添加到 Content View 中。一切都启用了用户交互!就这么简单,我没有什么复杂的事情发生!

什么是 UITableViewCell 停止按钮工作?

编辑:通过请求我初始化 UITableViewCells 的代码,自定义类称为 DownloadCell

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"DownloadCell";

    DownloadCell *cell = (DownloadCell *)[aTableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) 
    {
        UIViewController * cellController = [[UIViewController alloc] initWithNibName:@"DownloadCell" bundle:nil];
        cell = (DownloadCell *)cellController.view;
        [cellController release];
    }

    SoundLibrarianIPhoneAppDelegate * del = (SoundLibrarianIPhoneAppDelegate *)[UIApplication sharedApplication].delegate;

    DownloadQueue * dq = del.downloadQueue;

    DownloadJob * job = [dq getDownloadJob: indexPath.row];
    [job setDelegate:self];

    SoundInfo * info = [job sound];

    NSArray * seperated = [info.fileName componentsSeparatedByString: @"."];
    NSString * displayName = [seperated objectAtIndex:0];
    displayName = [displayName stringByReplacingOccurrencesOfString:@"_" withString:@" "];
    displayName = [displayName capitalizedString];

    [cell.titleLabel setText: displayName];
    cell.progressBar.progress = job.percentCompleted;
    [cell.progressLabel setText: [job getProgessText]];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.userInteractionEnabled = YES;

    [cell setDelegate:self];

    return cell;
}

【问题讨论】:

  • 您的IBAction 方法是在您的单元子类中还是在您的视图控制器中定义的?如何在表格视图中初始化单元格?
  • 我已编辑问题以包含您的问题!谢谢

标签: iphone uitableview uibutton


【解决方案1】:

似乎问题与我过于频繁地更新表格单元格有关,所以这会中断与单元格本身的任何交互

【讨论】:

    【解决方案2】:

    你有没有把这段代码放在表格视图中。? tableView.delegate=self; tableView.dataSource=self;

    谢谢, 巴拉特

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 1970-01-01
      • 2014-07-20
      • 2021-01-26
      • 2014-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多