繁体   English   中英

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

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

更新了我的.h和.m文件。 如前所述,一旦在第二个视图控制器中向表视图选择了行(多个),我就必须从ViewController1表视图获取数据(plist文件)。 在这里,我大部分时间都在挣扎:

#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

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

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

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

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

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

viewController.tableArray = selectedCellArray;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM