我如何将数据从SlideOut TableViewController传递到ViewController中嵌入的TableView

时间:2015-06-10 00:22:23

标签: ios uitabbarcontroller tableviewcell

  
    

更新了我的.h和.m文件。如上所述,我必须得到数据(plist     文件)一旦行(多个)有ViewController1表视图     已被选中到第二个视图控制器中的tableview。在这里,我几天都在奋斗:)

  
#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 个答案:

答案 0 :(得分:0)

假设您已在主表中进行了多项选择。 然后使用[mainTable indexPathsForSelectedRows];将给出所选单元格的indexPaths。

在转到下一个View Controller之前,使用以下命令传递包含所选单元格的数组:

1。)创建一个新数组,在其中循环遍历这些indexPath.row并从cupcakes数组中获取元素。

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

2。)通过在其中创建数组属性将其传递给下一个View Controller。

viewController.tableArray = selectedCellArray;