2
votes

The issue I am facing is thrown on only one device out of several test devices. All devices are iPhone 4s iOS 5.1.1 with another with iOS 6.0.1.

There are several answers to similar questions but none contain both symptoms.

The application has been written in Monotouch.

The symptoms of the issue are

The application will not change orientation on the affected device. An NSInvalidArgumentException is thrown when accessing certain views on the affected device.

The full exception is:

Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UITableViewCell updateConstraintsIfNeeded]: unrecognized selector sent to instance 0x4e07540

The Stack Trace is

MonoTouch.Foundation.MonoTouchException: Objective-C exception thrown.  Name: NSInvalidArgumentException Reason: -[UITableViewCell updateConstraintsIfNeeded]: unrecognized selector sent to instance 0x4c3cc20
  at MonoTouch.UIKit.UIView.UpdateConstraintsIfNeeded () [0x00010] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIView.g.cs:1626
  at XXXXXX.IOS.Dialogs.NewStyledMultilineElement.GetCell (MonoTouch.UIKit.UITableView tv) [0x0000f] in /Users/gavin/Perforce/Jon_PI-151_9051/XXXXXX/XXXXXX/v1.3.1/Mobile/XXXXXX/IOS/XXXXXX.Dialogs/My Work/WorkDetailDialogController.cs:30
  at MonoTouch.Dialog.DialogViewController+Source.GetCell (MonoTouch.UIKit.UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) [0x00029] in /Developer/MonoTouch/Source/MonoTouch.Dialog/MonoTouch.Dialog/DialogViewController.cs:340
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38
  at XXXXXX.IOS.Application.Application.Main (System.String[] args) [0x00000] in /Users/gavin/Perforce/Jon_PI-151_9051/Pall/XXXXXX/v1.3.1/Mobile/XXXXXX/IOS/XXXXXX.Application/Main.cs:28

The code that is causing the exception is

public class NewStyledMultilineElement : StyledMultilineElement
{
    public override UITableViewCell GetCell (UITableView tv)
    {
            UITableViewCell cell = base.GetCell(tv);
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            cell.UpdateConstraintsIfNeeded();
            return cell;
    }

    public NewStyledMultilineElement(string caption, string value) :base(caption,value)
    {
    }
}

The line that is throwing the error is cell.UpdateConstraintsIfNeeded();

The version information is

MonoDevelop 3.0.5 Runtime Mono 2.10.9 GTK 2.24.10 XCode 4.5.1 Monotouch 6.0.6

The settings on the affected device have been compaired to other devices that function as expected, with no obvious differences.

It is possible that the symptoms are for different issues. However, this is the only acception that is thrown.

Any help would be greatly appreciated

Further investigation has resolved the issue, temporarily. However the root cause has not been confirmed. The solutions are as follows

To resolve the orientation symptom, the following code was added to the base view controller from which all view controllers are dervied.

public override bool ShouldAutoRotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation) { return true; }

To resolve the NSInvalidArgumentException, StyledMultilineElement have been used instead of the derived class. This issue could be being caused by the GC, but varification of that would be appreciated.

The solutions solve the issue, without identifying the root causes. Any explination of why this is happening on only one device and not all would be helpful.

1

1 Answers

1
votes

You are using a feature of iOS6, which is constraint based layout. This is not available on iOS5. Hence, calling UpdateConstraintsIfNeeded() will fail an all devices running on iOS5.x and older.

See Apple's documentation: http://developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/updateConstraints

updateConstraintsIfNeeded Updates the constraints for the receiving view and its subviews.

  • (void)updateConstraintsIfNeeded Discussion Whenever a new layout pass is triggered for a view, the system invokes this method to ensure that any constraints for the view and its subviews are updated with information from the current view hierarchy and its constraints. This method is called automatically by the system, but may be invoked manually if you need to examine the most up to date constraints.

Subclasses should not override this method.

Availability Available in iOS 6.0 and later. Declared In UIView.h