UA-17470720-3

Jump to content


Photo
- - - - -

How to set Table style "grouped" for SCViewController


  • Please log in to reply
4 replies to this topic

#1 aaronium112

aaronium112

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 21 posts
Reputation: 7
Good

Posted 08 June 2013 - 01:00 PM

Hi. 

 

How do I set Table style "grouped" for SCViewController?

I'm actually using SCSearchViewController. =)

 

Thanks in Advance.



#2 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 08 June 2013 - 06:17 PM

HI aaronium112,

 

you can set the style of the table view a couple of different ways.

 

if you are using storyboards or xib files, you would use the object inspector to check the "grouped" property.  Just add your custom class to either that storyboard scene or xib file and things will work nicely. This is a good way to go.

 

if you are creating the controllers in code, then you would approach it generally like this:

 

SCTableView

 

SCTableViewController *newController = [[SCTableViewController alloc] initWithStyle:UITableViewStyleGrouped];

 

SCViewController

 

SCViewController *vc = [[SCViewController alloc]init];

UITableView *tblview = [[UITableView alloc]initWithFrame:vc.view.bounds style:UITableViewStyleGrouped];

vc.tableView = tblview;

vc.tableView.delegate = self;

 

 

Note, the grouping style for the tableView can only be set upon initialization of the tableview. Its a UITableView thing, not something inherent to STV.

 

hope that helps.



#3 aaronium112

aaronium112

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 21 posts
Reputation: 7
Good

Posted 09 June 2013 - 02:56 AM

Hi Everett,

 

Thanks for the reply, it doesn't solve the challenge in this specific situation.

I could have been more clear.

 

I am creating the SCSearchViewController from Storyboard.

Because SCSearchViewController is a subclass of SCViewController there no tableView to be set in the property inspector of the storyboard.



#4 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 09 June 2013 - 05:20 AM

HI aaronium112,

 

good catch!

 

SCSearchViewController inherits from SCViewController adding support for the UISearchBar.

 

Since your using the storyboard, I'd recommend you use this approach (also works for xib files):

 

Your storyboard scene is probably a blank UIViewController with your subclass assigned in the object inspector.  Your subclass should inherit from SCSearchViewController like this:

 

 

@interface ServiceBoardDrillDownController : SCSearchViewController

 

Step 1:

On the storyboard, from the controls palette add a UISearchBar at the top of your scene (or view).  There are two choices - pick Search Bar and Search Display Controller.  Connect this to your class via an outlet.  Call the outlet "searchBar".

 

Step 2:

On the storyboard, from the controls palette add a UITableView to your scene.  Align it below your search bar and make sure it takes up the remainder of the view (note: you can actually size it however you like, but keeping it simple for this example).  Connect this to your class via an outlet.  Call the outlet "tableView".

 

Step 3:

Add the outlets from these controls and connect them to your SCSearchViewController subclass. This can be in your public or private interface definition:

 

 

@interface ServiceBoardDrillDownController ()

 

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (weak, nonatomic) IBOutlet UISearchBar *searchBar;

 

@end

 

Note: the property names of the outlets are critical.  The SCSearchViewController will check to see if they already exist and if they do it will use them.  If not, it will create new ones automatically and add them to the view.

 

Note:  make sure you "connect" these outlets to the actual objects.

 

That should do it for storyboards or xib files.

 

Using code, since SCSearchViewController inherits from SCViewController, you can use the same code approach, just use the search controller:

 

SCSearchViewController *vc = [[SCSearchViewController alloc]init];

UITableView *tblview = [[UITableView alloc]initWithFrame:vc.view.bounds style:UITableViewStyleGrouped];

vc.tableView = tblview;

vc.tableView.delegate = self;

 

let me know if that is what you needed.


Edited by Everett, 09 June 2013 - 02:43 PM.


#5 aaronium112

aaronium112

    Jr. Member

  • STV 3.0 Std
  • PipPip
  • 21 posts
Reputation: 7
Good

Posted 13 June 2013 - 02:15 PM

That's it. Thanks Everett.


  • Everett likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users