Action on UIButton in UITableviewcell , Application got crash.

kunalthakkarkunalthakkar INMember ✭✭
edited October 2013 in Xamarin.iOS

Hi,
I put UIButton in UITableviewCell,Whenever i clicked on button application got crash and show me the following error.I am using XS 4.0.14.

mono-rt: Stacktrace:

mono-rt: at <0xffffffff>

mono-rt: at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr)

mono-rt: at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38

mono-rt: at MyJobCalls.Application.Main (string[]) [0x00008] in /Users/.. /Main.cs:16

mono-rt: at (wrapper runtime-invoke) .runtime_invoke_void_object (object,intptr,intptr,intptr)

mono-rt:
Native stacktrace:

=================================================================

Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.

=================================================================

Answers

  • sezamuzsezamuz BSMember ✭✭

    Pls show code where you create and add actions to button (+=) and contructor your cell

  • kunalthakkarkunalthakkar INMember ✭✭
    edited October 2013

    @ sezamuz: created GetCell method of UITableview as below:

        public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
            // if there are no cells to reuse, create a new one
            if (cell == null)
                cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
    
                UIButton btnUncheck = UIButton.FromType(UIButtonType.RoundedRect);
            btnUncheck.Frame = new RectangleF (200, 10, 100, 40);
            btnUncheck.SetTitle ("Clear All", UIControlState.Normal);  
            btnUncheck.Font = UIFont.FromName ("Helvetica-Bold", 15f);
            btnUncheck.SetBackgroundImage (UIImage.FromFile("Images/unchecked- box.png"),UIControlState.Normal);
            cell.AddSubview (btnUncheck);
            btnUncheck.TouchUpInside += (sender,e) => {
    
                Console.WriteLine("test");
    
            };
    
  • mannyvwmannyvw USMember

    its probably because you are adding multiple copies of the button everytime GetCell is called. It would be better to just add the button once when cell == null.

    hope it helps

  • kunalthakkarkunalthakkar INMember ✭✭
    edited October 2013

    @ mannyvw : Can you please post some code that can help me, i am new to xamarin.

  • mannyvwmannyvw USMember

    Try

        public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
                        {
                            UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
                            // if there are no cells to reuse, create a new one
                            if (cell == null)
                            {
                                cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
    
                                UIButton btnUncheck = UIButton.FromType(UIButtonType.RoundedRect);
                                btnUncheck.Frame = new RectangleF (200, 10, 100, 40);
                                btnUncheck.SetTitle ("Clear All", UIControlState.Normal);  
                                btnUncheck.Font = UIFont.FromName ("Helvetica-Bold", 15f);
                                btnUncheck.SetBackgroundImage (UIImage.FromFile("Images/unchecked- box.png"),UIControlState.Normal);
                                cell.AddSubview (btnUncheck);
                                btnUncheck.TouchUpInside += (sender,e) => {
    
                                    Console.WriteLine("test");
    
                                };
                            }
    
  • AshishjhaAshishjha USMember

    Hi mannyvw ,
    After implementing your code in my application, still i am facing the same issue. Can u suggest something else?

Sign In or Register to comment.