-1

I have one application and it is working fine in all version of iPhone except in iPhone 4. It is giving the below error.

-[UITableViewCell setLayoutMargins:]: unrecognized selector sent to instance 0x175f01b0

Can anyone help me what is the reason for this crash? How to resolve this issue?

serenesat
  • 4,611
  • 10
  • 37
  • 53
Naresh G
  • 21
  • 1
  • 5
  • 4
    My guess: `layoutMargins` is called, but it's only available since iOS8+ and you iPhone 4 is not on iOS8. – Larme May 18 '15 at 11:13
  • 1
    Check respondToSelector http://stackoverflow.com/questions/18365049/is-there-a-way-to-make-uitableview-cells-in-ios-7-not-have-a-line-break-in-the-s – Muhammad Adnan May 18 '15 at 11:15

1 Answers1

3

If you take a look at UIView.h or UIView documentation UIView layoutMargings property, you may notice that this property is only available for iOS 8 and above.

Once you are running your application on iPhone 4 and it is not intended to support this version of iOS (iOS 8)iPhone 4 versions of iOS supported, you should perform validations on your code to check if the API method is available. You can also check the version of iOS, it's your choice.

I don't know your implementation, but as a quick fix you can check if the instance of the cell responds to the selector, and perform the correct implementation.

Example:

UITableViewCell *tableViewCell = [[UITableViewCell alloc] init];
if ([tableViewCell respondsToSelector:@selector(setLayoutMargins:)]) {
    <# Your code here #>
}

To check the iOS version, you should use a macro or a function, just to keep your code simple. Just check here for more questions about: How to check iOS version? or check github repo carlj/CJAMacros

Hope that can help ;)

portella
  • 833
  • 6
  • 14