简体   繁体   English

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

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

updated my .h and .m files. 更新了我的.h和.m文件。 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. 如前所述,一旦在第二个视图控制器中向表视图选择了行(多个),我就必须从ViewController1表视图获取数据(plist文件)。 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

Suppose, you have made multiple selections in your main Table. 假设您在主表中进行了多个选择。 Then using [mainTable indexPathsForSelectedRows]; 然后使用[mainTable indexPathsForSelectedRows]; will give the indexPaths of the selected cells. 将给出所选单元格的indexPaths。

Before you go to next View Controller, pass a array containing selected cells using : 在转到下一个View Controller之前,请使用传递包含选定单元格的数组:

1.) Create a new array in which you loop through these indexPath.row and get the elements from cupcakes Array. 1.)创建一个新数组,在其中循环遍历这些indexPath.row并从纸杯蛋糕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. 2.)通过在其中创建数组属性,将其传递给下一个View Controller。

viewController.tableArray = selectedCellArray;

暂无
暂无

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

相关问题 如何将数据从Firebase iOS从TableViewController传递到另一个ViewController - How pass data from Firebase iOS from a TableViewController to another ViewController 如何使用委托将数据从第二个ViewController传递到TableViewController - How to pass data from 2nd viewcontroller to tableviewcontroller using delegates 如何将数据从视图控制器传递到另一个表视图? - How to pass data from a viewcontroller to another tableview? 斯威夫特:如何传递子视图控制器prepareForSegue的数据以更改父视图控制器表视图单元格的TextLabel? - Swift: How can I pass data from child viewcontroller prepareForSegue to change the TextLabel of a cell of parent viewcontroller tableview? TableView嵌套在CollectionViewCell中的VC,我如何将数据从TableView传递回ViewController - VC with TableView nested in CollectionViewCell, how can i pass data from TableView back to ViewController 如何从嵌入在ViewController中的tableViewController向该视图控制器发送信息? - how to send information from a tableViewController embedded in a ViewController to that view controller? 无法将 realm 数据从 tableViewController 传递到 viewController - Can't pass realm data from tableViewController to viewController 解除数据后如何从TableViewController传递数据? - How can I pass the data from a TableViewController when I dismiss it? 嵌入在 ViewController 中的 TableViewController - TableViewController embedded in ViewController 将数组数据从ViewController传递到TableView - Pass arrays data from a ViewController to a TableView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM