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

    macrumors newbie

    Joined:
    Jan 11, 2011
    #1
    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!
     
  2. macrumors 65816

    jnoxx

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

    Joined:
    Aug 26, 2010
    #3
    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.
     

Share This Page