viezel / NappUI

A collection of extended functionality for the UI components of Titanium SDK
Other
121 stars 34 forks source link

Incorrect way of checking for labels that have attributes #29

Open ludolphus opened 11 years ago

ludolphus commented 11 years ago

In the code for attributed labels (TiUILabel+Extend.m) checks for labels that have attributes by using this code:

    if(label.attributedText == nil) return;

But according to Apple's documentation the 'attributedText' is replaced as soon as the 'text' property is set:

In iOS 6 and later, assigning a new value to this property also replaces the value of the attributedText property with the same text, albeit without any inherent style attributes. Instead the label styles the new string using the shadowColor, textAlignment, and other style-related properties of the class.

Although the default is nil, after the label is created both text and attributedText will never be nil. Both properties set each others contents.

Apple docs: Assigning a new value to this property also replaces the value of the text property with the same string data, albeit without any formatting information

This issue results in labels not have explicitly set attributes to have an attributedText property anyway. As a result taps and long presses are handled by the module. And this causes a crash of the app as well (see separate issue) when tapping just outside to the right of a non-attributed label.