UA-17470720-3

Jump to content


Photo
- - - - -

Custom View for selecting options


  • Please log in to reply
26 replies to this topic

#1 Nicholas Watson

Nicholas Watson

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 28 posts
Reputation: 4
Good

Posted 16 January 2012 - 07:14 PM

Hello and thank you very much for creating Sensible TableView - it was worth every penny and has saved me loads of time.

I am very new to iOS development (learning using iOS5 using Storyboards) and I have made extensive use of the search on these forums so far and being able to figure out the solutions to many of the issues I have been facing.

Usually I wouldn't ask for help but I am really struggling with this one. Basically, I am calling my cells with a bound key on each one.

What I would like is a "selector style" cell where when clicked, it will load a view of options, but with a search bar to filter down the results. The reason for this is there are 89,000 rows! I will be using a web service to perform the queries and return JSON (I don't need to know all of that though, I will figure that out myself!)

So far, I am using the code:

SCSelectionCell *locationCell = [SCSelectionCell cellWithText:@"Location" withBoundKey:@"location" withLabelTextValue:nil];
locationCell.tag = 6;
[section addCell:locationCell]

When the cell is clicked, I'd like to load a view with the search bar and as the user types, it will narrow down results and finally when they click on a result, it will return the value back to Sensible TableView.

I have added a view with a Search Bar and Search Display Controller as this looks like the most promising way to handle this, however it's the whole linking to/from TableView that I'm struggling to figure out!

Thank you VERY much to whoever is able to answer me and sorry for taking up your time.
  • Tarek likes this

#2 Nicholas Watson

Nicholas Watson

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 28 posts
Reputation: 4
Good

Posted 19 January 2012 - 10:33 AM

Been at this for 5 solid days now and still struggling - hopefully I'll get there eventually.

I've tried many different things, including looking at the Custom Cells app, but for some reason it won't build for me in Xcode 4.2 with iOS 5 SDK, so it's proving a little difficult to figure out what's going on exactly.

I did read about an SCSelectionModel that was introduced and wondered if that was solution but can't really find any example of where it has been implemented.

Loading all the 81,000 locations into an array for user selection is always an option rather than requesting with JSON, but a search bar would be critical to filter down.

I'm after any solution really, well not even a solution - just some hints as to what I need to be looking at and experimenting with :)

Thanks again

#3 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 19 January 2012 - 02:53 PM

Hi Nicholas,

Thank you very much for all your complements, we really appreciate it :)

Regarding your question: SCSelectionModel does exist and is one of the newest additions to STV 2.0, but it's not the default model SCSelectionCell uses. What this means is that the automatically generated detail model used by SCSelectionCell is a normal SCTableViewModel, and thus it doesn't have the automatic searching and auto-sectioning functionality provided by SCSelectionModel. In STV 3.0 (beta should be out in about a month), you should be able to change the default detail model for any cell.

If you can't wait for STV 3.0, you could also achieve the same thing using STV 2.0 'custom views' feature. For a detailed example of using custom views instead of the automatically generated ones, please refer to our "Custom View App" sample. If you will take this approach, please tell me and I'll wrap up a sample for you so that you won't spend any more time struggling with this.

Hope this helps!

#4 Nicholas Watson

Nicholas Watson

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 28 posts
Reputation: 4
Good

Posted 19 January 2012 - 03:01 PM

tarekskr thank you VERY much for your response and I really appreciate it, as I have invested a lot of time in trying to figure this out.

I have had a look at the custom cells app and was really struggling to figure out how to implement this into my project. I am integrating STV with key bindings and iOS5/xCode 4.2 so I can't build to work out how exactly it is all working.

I definitely will be purchasing the upgrade to 3.0 as soon as it is out, but a month is quite a while away and I need to get this done sooner due to customer pressure (hence the time I'm investing in trying to figure this out).

A sample will be very much appreciated! Thanks again

#5 Nicholas Watson

Nicholas Watson

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 28 posts
Reputation: 4
Good

Posted 31 January 2012 - 02:12 PM

tarekskr, are you able to assist further with this please? I have been looking into this for 2 weeks now!

Thanks

#6 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 31 January 2012 - 02:22 PM

Hi Nicholas,

I apologize for the delay as I had to leave urgently and just got back yesterday. I should be able to give you a demo in the next couple of days. Thank you very much.

#7 Nicholas Watson

Nicholas Watson

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 28 posts
Reputation: 4
Good

Posted 31 January 2012 - 02:23 PM

no problem, thank you once again

#8 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 02 February 2012 - 06:03 PM

Hi again Nicholas,

Please find the sample app attached. Hope this helps!

#9 Nicholas Watson

Nicholas Watson

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 28 posts
Reputation: 4
Good

Posted 04 February 2012 - 08:38 AM

Absolutely spot on, thank you :)

#10 Nicholas Watson

Nicholas Watson

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 28 posts
Reputation: 4
Good

Posted 04 February 2012 - 10:43 AM

This is all working, one thing I was wondering if you have an easy answer on, is how to bind a function to the search bar changing (so I can load in custom results from a web service)

I've tried:

-(void)searchBar:(UISearchBar *)searchBar textDidChange:NSString *)searchText {

alas this does not work, am I trying to do this completely the wrong way or something?

Thanks

#11 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 04 February 2012 - 02:54 PM

You're welcome Nicholas :)

Regarding your question, if you want to supply your own custom results, then you should implement the SCTableViewModelDataSource method called 'tableViewModel:customSearchResultForSearchText:autoSearchResults:'. This method gives you the search results that STV automatically computed, and gives you the option between either modifying the computed search results or entirely providing your own ones.

Please tell me if that's what you're after.

#12 David DelMonte

David DelMonte

    Forum Master

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

Posted 05 February 2012 - 09:03 AM

Nicholas, if either of us figure out this method, could we let the other know. I'm trying to implement it too.
David

#13 poffel

poffel

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 116 posts
Reputation: 19
Good

Posted 05 February 2012 - 08:17 PM

Hi Tarek,

thanks for pointing me to this thread (from twitter B) ). I got your sample code and nearly managed to do what i want to achieve with it. But not for core data. I am a little lost now because i don't have a clue how to do what i want with entityDefinitons and core data. I think i need a reference to my current core data entity to pass it as a bound object?

The next prob is that i have a custom detail view as my app is going to be an iPad app. I do not know how to use SCSelectionModel as you did it in your sample with a customDetailTableViewModel... :-(

Thanks again for your great support!

#14 poffel

poffel

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 116 posts
Reputation: 19
Good

Posted 06 February 2012 - 10:27 PM

Yeah, finally worked it out ;-). Phew....

#15 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 07 February 2012 - 06:52 PM

Glad that worked out well :)

#16 poffel

poffel

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 116 posts
Reputation: 19
Good

Posted 07 February 2012 - 07:08 PM

hmm... i think a was a little quick with my last post :-(

i got it so far that my selection is nicely group by a given category, but i have problems with getting the selected values saved in my core data object...

I use the method
- (id)initWithTableView:(UITableView *)_modeledTableView withViewController:(UIViewController *)_viewController withBoundObject:(NSObject *)object withSelectedIndexesPropertyName:(NSString *)propertyName withItems:(NSArray *)sectionItems allowMultipleSelection:(BOOL)multipleSelection
but my selection are not saved. And i do not fully understand the withSelectedIndexesPropertyName. Do i have to add a extra property in my core data object as NSMutableSet?

#17 Nicholas Watson

Nicholas Watson

    Jr. Member

  • STV 3.0 Pro
  • PipPip
  • 28 posts
Reputation: 4
Good

Posted 10 February 2012 - 09:25 AM

I thought I was getting somewhere but seem to have hit a bit of a wall. So, essentially what I have is using the code you originally provided tarekskr but instead, as I'm using a storyboard I simply call a new view called locationSegue

[self performSegueWithIdentifier:@"locationSegue" sender:self]

This in turn, loads a new view with custom class "LocationTableView" and here is the code for the .h and .m files:

.h file

#import <UIKit/UIKit.h>
#import "SCTableViewModel.h"

@interface LocationTableView : UITableViewController <SCTableViewModelDelegate,SCTableViewModelDataSource,UISearchBarDelegate,UISearchDisplayDelegate> {
	SCTableViewModel *tableModel;
	NSMutableArray *searchItems;
}

@property (nonatomic,retain) NSMutableArray *searchItems;

@end

here is the .m code:

#import "LocationTableView.h"

@implementation LocationTableView
@synthesize searchItems;

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
	[super viewDidLoad];
	
	UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
	
	searchItems = [NSMutableArray arrayWithObjects:@"Red",@"Green",@"Blue",@"Black",@"Purple",@"Yellow",@"Orange",@"Magenta",@"White",nil];

	SCSelectionModel *selectionModel = [[SCSelectionModel alloc] initWithTableView:self.tableView withViewController:self withItems:searchItems];
	
	selectionModel.searchBar = searchBar;
	
	tableModel = selectionModel;
	
	[self.view addSubview:searchBar];
}
- (void)tableModel:(SCTableViewModel *)tableModel customSearchResultForSearchText:(NSString *)searchText autoSearchResults:(NSArray *)autoSearchResults {
	NSLog(@"Search initialized");
}

@end

Basically, my understanding is that customSearchResultForSearchText function should NSLog the text I have there, but it does not.

Interestingly, the search results it does return aren't accurate. Searching "G" will return "Orange" and "Magenta" but not "Green" and searching "Bl" will only return "Black" but not "Blue"

Thank you again very much for your help, I'd be nowhere near where I am now without it.

#18 poffel

poffel

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 116 posts
Reputation: 19
Good

Posted 13 February 2012 - 06:06 PM

*bump*

still struggling with this one :-(. Can't get my selections saved to the bound coredata object...
  • dev1 likes this

#19 poffel

poffel

    Advanced Member

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 116 posts
Reputation: 19
Good

Posted 14 February 2012 - 09:23 AM

i am on the right track now i guess. Will provide my solution in the next two days (hopefully) ;-)

#20 Tarek

Tarek

    Forum Admin

  • Administrators
  • 3670 posts
Reputation: 452
Popular

Posted 14 February 2012 - 04:58 PM

Hi Lars,

Please tell me if you need any help.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users