Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Mac2011

macrumors newbie
Original poster
Jan 11, 2011
11
0
So i've got a table view with several sections and i want to make a filter so only a few sections are displayed. I've already created a view so the sections can be chosen. There I've got a table where you can select the wanted sections for the first view. and now i don't know how to use a protocol or delegate to send the data back to my previous view.
so here is the code of the fist view:

Code:
@implementation TableViewController

- (NSArray *)sections {
	
	
	if (!sections) {
		
		
		sections = //creating sections
	}
	return sections;
}

....

#pragma mark -
#pragma mark View lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
       
	
    UIBarButtonItem *settingsButtonItem = [[UIBarButtonItem alloc]
										   initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:@selector(filterview)];
    self.navigationItem.leftBarButtonItem = settingsButtonItem;
    [settingsButtonItem release];
  
}

...

#pragma mark -
#pragma mark Table view delegate

- (void)filterview
{

	SettingsTableViewController *settingsTableViewController = [[SettingsTableViewController alloc] init];
    [[self navigationController] pushViewController:settingsTableViewController animated:YES];
	[sections release];
    [settingsTableViewController release];
	
}

and here is the code of the FilterViewController which will be displayed:

Code:
@implementation SettingsTableViewController
- (NSMutableArray *)selections
{
       //here are all selected items saved
	if (!selections) {
	selections = [[NSMutableArray alloc] init];
	}
	return selections;
}

- (void)viewDidLoad {
    [super viewDidLoad];
	self.title = @"Settings";
	self.navigationItem.hidesBackButton = YES;
	
	
	UIBarButtonItem* saveItem = [[UIBarButtonItem alloc]  initWithBarButtonSystemItem:UIBarButtonSystemItemSave 
																			   target:self action:@selector(/*some method to send data back*/)];
	self.navigationItem.rightBarButtonItem = saveItem;
	[saveItem release];


and now i want to send this data (selections) back, how do I do this? HELP!
 
Last edited:
If all your doing is filtering sections there is no need for a new view. You can redraw your original UITableView and then filter out the sections.


Back to what your trying to do. If you know you want to use a delegate \ protocol paradigm however you're unsure how to implement such a thing I would suggest looking in the apple developer center a quick search of protocol returned this http://developer.apple.com/library/...doc/uid/DTS40009775-Intro-DontLinkElementID_2, note this will only show you how to implement a protocol, implementing a delegate is even easier.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.