BillTrackerViewController

BillTrackerViewController

本文介绍了Segue不会传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将另一个名为BillTrackerViewController的视图控制器中的数组设置为位于主类MainViewController中的名为billtrackertablevalues的NSMutableArray的值。我打算将BillTrackerViewController中的数组用作那里的UITableView的数据。但是,当我尝试设置该数组,table_items和segue的值时,该表未显示任何内容。但是,billtrackertablevalues的值已正确填充,并且不为空。

I am trying to set an array in another view controller, named BillTrackerViewController, to the values of an NSMutableArray called billtrackertablevalues, located in the main class, MainViewController. I intend to use the array in BillTrackerViewController as data for the UITableView there. However, when I try to set the value of that array, table_items, and segue, the table doesn't show anything. However, the value of billtrackertablevalues is properly filled, and is NOT null.

这是我的MainViewController代码:

Here is my code for MainViewController:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    if([segue.identifier isEqualToString:@"toBillTracker"]) {
        PFQuery *query = [PFQuery queryWithClassName:@"Resolution"];
        [query whereKey:@"event" equalTo:event_name_label.text];
        [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
            if (!error) {
                for (PFObject *object in objects) {
                    [billtrackertablevalues addObject:[NSString stringWithFormat:@"%@\nPro: %@\nCon: %@\nResult: %@",[object objectForKey:@"resolution_name"], [object objectForKey:@"resolution_pro_speaker"], [object objectForKey:@"resolution_con_speaker"], [object objectForKey:@"resolution_result_id"]]];
                }
                NSLog(@"%@", billtrackertablevalues);
                BillTrackerViewController *controller=(BillTrackerViewController *)segue.destinationViewController;
                controller.table_items = [[NSMutableArray alloc] init];
                controller.table_items = billtrackertablevalues;
            } else {
                NSLog(@"Error: %@ %@", error, [error userInfo]);
            }
        }]; 
    }
}

这是我的BillTrackerViewController代码:

And here is my code for BillTrackerViewController:

#import "BillTrackerViewController.h"
#import "Parse/Parse.h"

@interface BillTrackerViewController ()

@end

@implementation BillTrackerViewController

@synthesize billView;
@synthesize refreshButton;

@synthesize table_items;

- (void)viewDidLoad
{
    [super viewDidLoad];
    [billView reloadData];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) { }
    return self;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

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

- (UITableViewCell *)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainCell"];

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

    NSString *cellText = table_items[indexPath.row];
    cell.textLabel.text = cellText;
    return cell;
}

@end

再一次, BillTrackerViewController不会加载值,但是我的初始数组billtrackertablevalues已填充。

Once again, the table on BillTrackerViewController doesn't load values, but my initial array, billtrackertablevalues, is filled.

在此先感谢大家!

推荐答案

更改以下代码:-

controller.table_items = [[NSMutableArray alloc] init];
controller.table_items = billtrackertablevalues;

如下所示:-

controller.table_items = [[NSMutableArray alloc] initWithArray:billtrackertablevalues];

然后在viewDidLoad中的BillTrackerViewController上执行 NSLog 方法,让我知道。希望它能工作。

After that do NSLog at BillTrackerViewController in viewDidLoad method and let me know. Hope it will work.

这篇关于Segue不会传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 13:10