Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example Project Terminated With Xcode 4.5 and iOS 6 Simulator #74

Closed
so898 opened this issue Aug 16, 2012 · 3 comments
Closed

Example Project Terminated With Xcode 4.5 and iOS 6 Simulator #74

so898 opened this issue Aug 16, 2012 · 3 comments

Comments

@so898
Copy link

so898 commented Aug 16, 2012

Just trying the last version of the example project in the source code list.
Xcode gives this:
2012-08-17 03:01:36.448 AttribLbl[24381:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'textAlignment does not accept NSTextAlignmentJustified'
*** First throw call stack:
(0x17e6552 0x11cce7e 0x17e632b 0x55bc88 0x739d 0x2745 0x241d 0x3ff2e7 0x3ff8d7 0x400adb 0x411e15 0x412d4b 0x404828 0x2121e39 0x2121b10 0x175c1b5 0x175bf22 0x178d176 0x178c504 0x178c3db 0x40030a 0x40218c 0x233d 0x2275)
libc++abi.dylib: terminate called throwing an exception
However, everything is fine with Xcode 4.4.1 and iOS 5.1 simulator.
So that means OHAttributedLabel could not be used in iOS 6 anymore?

AliSoftware added a commit that referenced this issue Aug 16, 2012
…S6 SDK. Use setTextAlignment:lineBreakMode: on your NSAttributedString instead.

(This fixes issue #74)
@AliSoftware
Copy link
Owner

As it seems by the iOS6 Prerelease documentation, the type of the textAlignment property of UILabel is now NSTextAlignment and not UITextAlignment. (And as with the new LLVM compiler included with the latest version of Xcode, the checkings on the enum values are stronger anyway)

As I use this UITextAlignmentJustify pseudo-constant in my example project (see the fillLabel1 method) this causes the runtime error you have.

I just modified the class so that it now triggers an compilation error ("unavailable" attribute) if you try to use this constant while compiling with the iOS6 SDK, and a depreciation warning anyway before iOS6 SDK. This will show you exactly where the constant is used in your own code (if used) and where it should be replaced by the new way to do text justification, namely applying the text alignment attribute to your whole NSAttributedString instead of using the UILabel property.

I also updated the example project to apply to this new rule, so you can get inspiration from here about this correct way of setting justification on your text, namely calling setTextAlignment:lineBreakMode: on your NSAttributedString.

Note that I have tested it under the iOS6 SDK (as I only have the iOS6 SDK on my Mac at work, not here) so let me know if it fixed your issue. Thanks.


PS: if you plan to distribute an iOS6-only application, as UILabel now support NSAttributedString, you should use UILabel directly instead of OHAttributedLabel as it is now natively supported by the OS.

@so898
Copy link
Author

so898 commented Aug 17, 2012

Thanks for fixing the code

Seems like there still are some problem in the textAlignment part.

-(IBAction)changeHAlignment
{
label2.textAlignment = (label2.textAlignment+1) % 4;
}

In this part, when I try to run it twice, the iOS 6 Simulator crash and give this error message:
2012-08-17 15:02:41.157 AttribLbl[25453:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'textAlignment does not accept NSTextAlignmentJustified'
*** First throw call stack:
(0x17e6552 0x11cce7e 0x17e632b 0x55bc88 0x739d 0x2aef 0x11e0705 0x405450 0x4053e8 0x4c5b21 0x4c607f 0x4c51e8 0x434e0f 0x435022 0x412eaa 0x404828 0x2121e39 0x2121b10 0x175c1b5 0x175bf22 0x178d176 0x178c504 0x178c3db 0x2120823 0x21206a8 0x40218c 0x233d 0x2275)
libc++abi.dylib: terminate called throwing an exception

I think there might be other problem in OHAttributedLabel about the textAlignment.
Maybe it is because you change the define of the UITextAlignmentJustify.

I am just learning CoreText right now, so I can not give any suggestions about it, sorry.

@AliSoftware
Copy link
Owner

Errr I don't think you really understand how to interpret the exception. The cause of this exception is obvious: this is not related to the change made in UITextAlignmentJustify constant or to OHAttributedLabel itself, but still related to the same issue, namely that the example project tries to set the textAlignment value of UILabel to the value 3 (aka my UITextAlignmentJustify constant or the NSTextAlignmentJustify SDK constant), value which is now forbidden by the runtime since SDK 6 (but wasn't checked at runtime before iOS6).

So this is exactly the same problem as before, and related to the fact that the example project uses the value 3 for textAlignment property in setHAlignment example code, which now triggers an exception in SDK6.

There is an obvious easy fix: avoid using the UITextAlignmentJustify value (aka (int)3) in your projects as explained before. I changed the example code in the fillLabel1 in the previous commit but forgot the case in the changeHAlignment example code that also tries to use this value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants