2

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.

4

1 回答 1

1

您正在使用 iOS6 的一项功能,即基于约束的布局。这在 iOS5 上不可用。因此,UpdateConstraintsIfNeeded()在 iOS5.x 和更早版本上运行的所有设备都会调用失败。

请参阅 Apple 的文档:http: //developer.apple.com/library/ios/#documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/updateConstraints

updateConstraintsIfNeeded 更新接收视图及其子视图的约束。

  • (void)updateConstraintsIfNeeded 讨论 每当为视图触发新的布局传递时,系统都会调用此方法以确保使用来自当前视图层次结构及其约束的信息更新视图及其子视图的任何约束。此方法由系统自动调用,但如果您需要检查最新的约束,可以手动调用。

子类不应覆盖此方法。

可用性 适用于 iOS 6.0 及更高版本。在 UIView.h 中声明

于 2012-12-13T12:37:40.380 回答