How i pass Data from SlideOut TableViewController to TableView embedded in ViewController

132 views Asked by At

updated my .h and .m files. As mentioned i have to get the data (plist file) from the ViewController1 tableview once rows (multiple) have been selected to the tableview in the second view controller. Here i struggle mostly since days :)

#import "ViewController1.h"


@interface UIViewController () <UITableViewDataSource, UITableViewDelegate> @end

@implementation ViewController1 {
    NSArray *tableData; }


- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"TableData" ofType:@"plist"];

    NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:path];
    tableData = [dictionary objectForKey:@"Cupcakes"];}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated. }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [tableData count]; }

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = [tableData objectAtIndex:indexPath.row];


    return cell;

     }

@end

import "ViewController.h"
#import "SWRevealViewController.h"


@interface ViewController ()

@end

@implementation ViewController


@synthesize count;
@synthesize countLabel;
@synthesize negative;



- (void)viewDidLoad
{

    negative = TRUE;

    [super viewDidLoad];

    _barButton.target = self.revealViewController;
    _barButton.action = @selector(revealToggle:);

    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];




  }

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

#pragma mark - TableView Deletage and Datasouce methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {

    }
}

- (IBAction)plus:(UIButton*)sender{
    count++;
    [self displayCount];
}

- (IBAction)minus:(UIButton*)sender {
    count--;

    if (negative){         //This simply checks if negative mode is offsw_rear
        if (count < 0){    //and if count is negative
            count = 0;     //sets it back to zero
        }}
    [self displayCount];
}

- (void)displayCount {
    [self.countLabel setText:[[NSString alloc]initWithFormat:@"%ld", (long)self.count]];
}


- (UIViewAnimationOptions) closeAnimationCurve {
    return UIViewAnimationOptionCurveEaseOut;
}

// Enabling Deepnes on left menu
- (BOOL)deepnessForLeftMenu
{
    return YES;
}

// Enabling Deepnes on left menu
- (BOOL)deepnessForRightMenu
{
    return YES;
}

// Enabling darkness while left menu is opening
- (CGFloat)maxDarknessWhileLeftMenu
{
    return 0.50;
}

// Enabling darkness while right menu is opening
- (CGFloat)maxDarknessWhileRightMenu
{
    return 0.5;
}

@end
1

There are 1 answers

1
Jen Jose On

Suppose, you have made multiple selections in your main Table. Then using [mainTable indexPathsForSelectedRows]; will give the indexPaths of the selected cells.

Before you go to next View Controller, pass a array containing selected cells using :

1.) Create a new array in which you loop through these indexPath.row and get the elements from cupcakes Array.

NSMutableArray *selectedCellArray = [[NSMutableArray alloc] init];
for(NSIndexPath *index in [mainTable indexPathsForSelectedRows])
{
   [selectedCellArray addObject: cupcakes[index.row]];
}

2.) Pass this to your next View Controller by creating a array property in it.

viewController.tableArray = selectedCellArray;