How do you send data to the previous view?

Discussion in 'iOS Programming' started by Mac2011, Jan 11, 2011.

  1. Mac2011, Jan 11, 2011
    Last edited: Jan 11, 2011

    Mac2011 macrumors newbie

    Jan 11, 2011
    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:

    @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:

    @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!
  2. jnoxx macrumors 65816


    Dec 29, 2010
    Aartselaar // Antwerp // Belgium
    How bout making a reference to that view.
    And do like in FirstView
    [secondView arrayName]
    or secondView.arrayName? :)
  3. Sykte macrumors regular

    Aug 26, 2010
    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, note this will only show you how to implement a protocol, implementing a delegate is even easier.

Share This Page