UA-17470720-3

Jump to content


Photo
- - - - -

Showing cells based on a UISwitch


  • Please log in to reply
8 replies to this topic

#1 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 25 October 2011 - 11:42 AM

Tarek, if this capability is there, then please forgive.

I have an app that has too many cells. I'd like to show a set of cells based upon switches.

For example, one-time vs recurring. If the user selects "one-time", then a set of cells opens. Alternatively, if the user selects recurring, a different set of cells open.

This is all within the same tableView.

David

#2 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 25 October 2011 - 01:03 PM

Hi David,

The most straight forward way to do this using STV is by implementing the 'valueChangedForRowAtIndexPath' delegate method, then rebuild the section's cells (preferably have the changing cells in a separate section, other than the one containing the switch cell) and call [tableViewModel.modeledTableView realoadSections:...]. If you're still stuck with this, please provide me with some specifics and I'll give you some sample code to help you out.

#3 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 25 October 2011 - 01:28 PM

Thanks Tarek, I'll give it a shot.

Re. UISwitch - I presume that in iOS5, there is still no neat way to change the values of the switch (e.g. YES/NO).

Re UISlider, is there a sample of how to capture the value of the slider in a core data model?
Also can you modify a slider cell to have the equivalent of less < > more to the left/right of the slider?


Looking at Apple's UICatalog sample (great resource), I can see how to put the cell legend below the cell, but it would be nice to have it around the cell. I suppose I can make a custom slider..

#4 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 28 October 2011 - 12:09 AM

Hi David,

Re. UISwitch - I presume that in iOS5, there is still no neat way to change the values of the switch (e.g. YES/NO).
...
Also can you modify a slider cell to have the equivalent of less < > more to the left/right of the slider?

iOS 5 support full customization of its controls. For more information, please refer to the WWDC videos or if you wish you can search online for more material.

Re UISlider, is there a sample of how to capture the value of the slider in a core data model?

You can always access the value of your slider by using the following:
...
float sliderValue = mySiderCell.slider.value;
...

Hope this helps.

#5 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 28 October 2011 - 12:15 AM

Interesting.. Thanks a lot as usual..

#6 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 08 November 2011 - 12:17 PM

Tarek, I've gotten some feedback on my new app. One comment was that there may be too many fields for some users.

I was thinking of setting up preferences so that people can choose which fields to display.

I presume that I would do this in a dictionary.

Could I ask you to provide a snippet to show how to test for a value, and display the cell depending upon that value?

For example, lets say I have these fields in a tableview:

First Name
Last Name
Address 1
Address 2
etc.

I want to be able to hide address 2, if the user doesn't want to show it.. I still want to keep track in Core Data though in case they change their mind..

Many thanks!!

David

#7 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 November 2011 - 05:12 PM

Hi David,

I am assuming here you're working with class definitions & Core Data (if not, please correct me):

The easiest way I can think of is to test your conditions while creating your propertyNames string array. For example:
...
NSMutableArray *propertyNames = [NSMutableArray arrayWithArray:[NSArray arrayWithObjects:@"firstName", @"lastName", nil]];
if(myCondition)
  [propertyNames addObject:@"Address 1"];
//etc.
...
SCClassDefinition *myClassDef = [SCClassDefinition definitionWithEntityName:@"MyEntity" withManagedObjectContext:myManagedContext withPropertyNames:propertyNames];
...

Hope this helps :)

#8 David DelMonte

David DelMonte

    Forum Master

  • STV 4.0 Pro
  • PipPipPipPipPipPipPip
  • 527 posts
Reputation: 41
Excellent

Posted 14 November 2011 - 05:29 PM

very cool. Thanks Tarek.. (Sometimes I "over think" and nothing happens). As usual, your solution is simple and elegant.

#9 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 15 November 2011 - 02:17 AM

Thanks David, you're welcome! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users