我创建了下面的代码来显示按钮UITableView
。我想为表格中的每个特定单元格添加点击事件,以通过点击该按钮来访问谷歌链接。如何将点击事件添加到特定单元格的按钮选项中并访问谷歌链接?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UIButton *button =[[UIButton alloc]initWithFrame:CGRectMake(5,5,40,40)];
[button addTarget:self action:@selector(buttonpressed:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"lori"] forState:UIControlStateNormal];
[button setTag:9001];
[cell addSubview:button];
[cell setIndentationWidth:45];
[cell setIndentationLevel:1];
cell.textLabel.text = [thearray objectAtIndex:indexPath.row];
return cell;
}
-(void) buttonpressed:(UIButton *)sender {}