vikeyToy 2012-09-29 03:30 采纳率: 0%
浏览 8514
已采纳

UITableView单击事件,相应的时间无法响应

在程序里创建了一个按钮和表,我想实现的是点击table里面的任何一行和按钮,相应的事件就会响应。我先在每行里面设置了tag:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath {
static NSString *LabelCellIdentifier = @"cell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:LabelCellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault     reuseIdentifier:LabelCellIdentifier];


}

if (indexPath.row <= [_arrayMp3Link count]) {

cell.textLabel.text = [_arrayMp3Link objectAtIndex:indexPath.row];

 }


NSInteger count = 1;
for (NSInteger i = 0; i < indexPath.section; i++) {
count += [[tableView dataSource] tableView:tableView numberOfRowsInSection:i];
}
count += indexPath.row;

cell.tag = count;



return cell;

然后把事件放到每个按钮里,但是没有实现:

(IBAction)doDownload:(id)sender {

if(cell.tag==1)
{
[[UIApplication sharedApplication]openURL:[NSURL   URLWithString:@"http://www.google.com"]]; 
}
  • 写回答

1条回答

  • MrsSeven7 2012-10-08 01:52
    关注

    声明一个全局变量int

    int rowNo;
    

    然后在didSelectRowAtIndexPath中赋值

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     rowNo= indexPath.row; }
    

    选中行的index

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     rowNo= indexPath.row; }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器