0

I am getting json data where i also get value for what kind of accessory type i have to show for each row. It comes as follows:

{
accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}

When I directly assign this value to cell.accessoryType, it does not show up.

I have tried prining it as a String, and it prints correctly. How should I proceed? Can I convert NSSTring to UITableViewCellAccessoryType?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Nikita P
  • 4,226
  • 5
  • 31
  • 55
  • possible duplicate of [Convert objective-c typedef to its string equivalent](http://stackoverflow.com/questions/1094984/convert-objective-c-typedef-to-its-string-equivalent) – Lord Zsolt Jun 14 '14 at 17:11

1 Answers1

0

UITableViewCellAccessoryDetailDisclosureButton is an NSInteger from an enum.

cell.accessoryType expect an NSInteger as well. Since you don't know what integer represents the button types, you can't really convert directly between NSString and NSInteger.

Your options are:

  1. Instead of seding UITableViewCellAccessoryDetailDisclosureButton string in the JSON, you could send the integer value which represents in (not recommended, it might change since some button types get deprecated).
  2. Verify the string like

.

NSString *accessoryString = [json objectForKey:accessoryType];

if (accessoryString isEqualToString:@"UITableViewCellAccessoryDetailDisclosureButton"]   {
    cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
} else {
    //Other actions
}
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76
  • That was what I was thinking. I had kept this option as the last. Isn't there any better way? – Nikita P Jun 14 '14 at 17:07
  • Never mind, your case is the same as this question: http://stackoverflow.com/questions/1094984/convert-objective-c-typedef-to-its-string-equivalent And the answer for that is no. – Lord Zsolt Jun 14 '14 at 17:08