请教个tableview使用的问题?

riveryh 2015-11-04 10:18:39
刚学ios编程,想实现以下功能:一个tableview分成3列,第一列是imageview,第二列是label,第三列是button,当点击到第一列和第二例时,显示图片的详细信息,当点击第三列时执行删除这一行操作。我在一个cell中放置了这三个元素,并在tableview的controller中增加以下内容:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *TableCellIdentifier = @"ListItemCell";
ItemCellTableViewCell *cell = (ItemCellTableViewCell*)[tableView dequeueReusableCellWithIdentifier:TableCellIdentifier];
if (cell == nil)
{
NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"ItemCellTableViewCell"
owner:self options:nil];
cell = [array objectAtIndex:0];
}

NSUInteger row = [indexPath row];

//给前面两列赋值
[cell.imgvwPhoto sd_setImageWithURL:[self.muArrayheadPic objectAtIndex:row] placeholderImage:[UIImage imageNamed:@"pic_loading.png"]];
cell.tvDesc.text = [self.muArrayDesc objectAtIndex:row];
// butto的点击事件
[cell.btnOperflag addTarget:self action:@selector(btnOperflagClicked:) forControlEvents:UIControlEventTouchUpInside];
cell.btnOperflag.tag = row;
return cell;
}
- (IBAction)btnOperflagClicked:(UIButton *)sender{
NSString * strInfo ="1234";
UIAlertView * alter = [[UIAlertView alloc] initWithTitle:@"删除信息" message:strInfo delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alter show];
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger row = [indexPath row];
NSString * strinfo =[self.muArrayFriendID objectAtIndex:row];
UIAlertView * alter = [[UIAlertView alloc] initWithTitle:@"选中的行信息" message:strinfo delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[alter show];

}
测试中发现点击前两列能正常显信息,但点击button则没有任何反应,请教各位老大该怎么解决?多谢!
...全文
114 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2015-11-09
  • 打赏
  • 举报
回复
将button的响应事件在自定义cell中添加,然后button响应,说不好听就是把事件全部丢到cell里面。 但是这不符合设计,正确的设计是button响应了,通过代理通知控制器做事情

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧