开发者社区> 问答> 正文

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"]]; 
}

展开
收起
爵霸 2016-05-27 16:01:01 1896 0
1 条回答
写回答
取消 提交回答
  • 声明一个全局变量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; }
    2019-07-17 19:18:08
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载