您的位置:首页 > 产品设计 > UI/UE

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)

            {

               

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息