【发布时间】:2012-07-02 02:51:17
【问题描述】:
我创建了以下代码来显示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 {}
【问题讨论】:
-
哇...您的格式有问题。
-
是的,我知道我没有得到 ..how to put spase between it.but 你能理解吗?
-
不,它只是不可读。
-
您的代码似乎有点奇怪。我删除了第二种方法,因为它没有意义。以这种方式,其他人可以理解代码。附:如果您愿意,您可以回滚到之前版本的代码。
标签: ios uitableview hyperlink uibutton