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; }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容