xamarin ios 怎样捕获UITableViewCell中button的点击事件
2017-08-16 11:37
405 查看
/// <summary>
/// 在每行中添加数据
/// </summary>
/// <param name="tableView"></param>
/// <param name="indexPath"></param>
/// <returns></returns>
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell(CellIdentifier1) as CustomCell;
if (cell == null) {
cell = new CustomCell(CellIdentifier1);
cell.UpdateCell(Id_str[indexPath.Row].ToString(), Image_str[indexPath.Row].ToString(), Title_str[indexPath.Row].ToString(), Title_str_2[indexPath.Row].ToString());
}
//定义用于点击的按钮
UIButton cellbtn = new UIButton();
cellbtn .Frame = new CGRect(5, 6, 310, 50);
//为按钮添加点击事件以及tag值
cellbtn .AddTarget(btn_onclick, UIControlEvent.TouchUpInside);
cellbtn .Tag = indexPath.Row;
//将按钮添加到cell中
cell.ContentView.AddSubview(cellbtn );
return cell;
}
//按钮的点击事件
public void btn_onclick(object sender, EventArgs e)
{
UIButton str_newbtn = (UIButton)sender;
if (str_newbtn.Tag == 1)
{
}
else if (str_newbtn.Tag == 2)
{
}
else if (str_newbtn.Tag == 3)
{
}
}
/// 在每行中添加数据
/// </summary>
/// <param name="tableView"></param>
/// <param name="indexPath"></param>
/// <returns></returns>
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.DequeueReusableCell(CellIdentifier1) as CustomCell;
if (cell == null) {
cell = new CustomCell(CellIdentifier1);
cell.UpdateCell(Id_str[indexPath.Row].ToString(), Image_str[indexPath.Row].ToString(), Title_str[indexPath.Row].ToString(), Title_str_2[indexPath.Row].ToString());
}
//定义用于点击的按钮
UIButton cellbtn = new UIButton();
cellbtn .Frame = new CGRect(5, 6, 310, 50);
//为按钮添加点击事件以及tag值
cellbtn .AddTarget(btn_onclick, UIControlEvent.TouchUpInside);
cellbtn .Tag = indexPath.Row;
//将按钮添加到cell中
cell.ContentView.AddSubview(cellbtn );
return cell;
}
//按钮的点击事件
public void btn_onclick(object sender, EventArgs e)
{
UIButton str_newbtn = (UIButton)sender;
if (str_newbtn.Tag == 1)
{
}
else if (str_newbtn.Tag == 2)
{
}
else if (str_newbtn.Tag == 3)
{
}
}
相关文章推荐
- 在ListView中捕获button或其他clickable属性设为true的空间的点击事件
- UITableViewCell内放置复杂结构的subview,但subview中的Button不响应点击事件
- iOS Block 处理UITableViewCell上button的点击事件
- Button点击事件无响应的问题
- unity3D 长按Button使button失效点击事件
- 关于在自定义View中添加Button按钮以及实现点击事件
- Android之Button点击事件处理的几种方式
- Android中5种Button点击事件的实现方法
- C# 事件穿透 事件冒泡 鼠标点击后在父级控件捕获
- 自定义UITableViewCell 上的多个按钮点击事件处理
- 微信小程序例子——实现button点击事件改变数据值
- 自定义CursorAdapter,实现ListView中动态加载button,和点击事件
- tableHeaderView中的button点击事件不响应
- 解决UIScrollView把uitableviewcell的点击事件屏
- 关于Button点击两次才响应事件相关问题
- Android Listview中Button按钮点击事件冲突解决办法
- Button点击事件
- Android Button的点击事件
- Android button按钮点击过快造成多次事件
- 服务器控件button点击时执行脚本弹出提示对话框Button2.Attributes.Add("onclick","事件")