PFQueryTableView没有更新/如何更新

时间:2013-04-25 22:02:07

标签: ios parse-platform

新的一天新问题我想。

我正在使用带有5个按钮的JASidePanel,每个按钮都会更改变量的值。 变量在MyTableController.m中用作parseClassName。

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom the table

        // The className to query on
        if (_sDay==Nil) {
            self.parseClassName = @"Montag";
        }else{
        self.parseClassName = self.sDay;
        }
        // The key of the PFObject to display in the label of the default cell style
        self.textKey = @"Fach";

        // Whether the built-in pull-to-refresh is enabled
        self.pullToRefreshEnabled = YES;

        // Whether the built-in pagination is enabled
        self.paginationEnabled = NO;

        // The number of objects to show per page
        self.objectsPerPage = 5;
    }
    return self;
}




- (void)viewDidLoad {
    [super viewDidLoad];

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"hintergrund"]];
    imageView .frame = CGRectMake(0,0,255,458);
    [self.view addSubview:imageView];


    CGRect frameBtn = CGRectMake(0.0f, 0.0f, 254.0f, 50.0f);
    self.bMonday = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.bMonday setBackgroundImage:[UIImage imageNamed:@"button_rechts_1"] forState:UIControlStateNormal];
    [self.bMonday setTitle:@"Montag" forState:UIControlStateNormal];
    [self.bMonday setFrame:frameBtn];
    [self.bMonday addTarget:self
                     action:@selector(monday:)
                 forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.bMonday];



    CGRect frameBtn2 = CGRectMake(0.0f, 50.0f, 254.0f, 50.0f);
    self.bTuesday  = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.bTuesday setBackgroundImage:[UIImage imageNamed:@"button_rechts_1"] forState:UIControlStateNormal];
    [self.bTuesday setTitle:@"Dienstag" forState:UIControlStateNormal];
    [self.bTuesday setFrame:frameBtn2];
    [self.bTuesday addTarget:self
                      action:@selector(tuesday:)
           forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:self.bTuesday];


    CGRect frameBtn3 = CGRectMake(0.0f, 100.0f, 254.0f, 50.0f);
    self.bWendsday = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.bWendsday setBackgroundImage:[UIImage imageNamed:@"button_rechts_1"] forState:UIControlStateNormal];
    [self.bWendsday setTitle:@"Mittwoch" forState:UIControlStateNormal];
    [self.bWendsday setFrame:frameBtn3];
    [self.bWendsday addTarget:self
                       action:@selector(wendsday:)
           forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:self.bWendsday];


    CGRect frameBtn4 = CGRectMake(0.0f, 150.0f, 254.0f, 50.0f);
    self.bThursday = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.bThursday setBackgroundImage:[UIImage imageNamed:@"button_rechts_1"] forState:UIControlStateNormal];
    [self.bThursday setTitle:@"Donnerstag" forState:UIControlStateNormal];
    [self.bThursday setFrame:frameBtn4];
    [self.bThursday addTarget:self
                       action:@selector(thursday:)
           forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:self.bThursday];


    CGRect frameBtn5 = CGRectMake(0.0f, 200.0f, 254.0f, 50.0f);
    self.bFriday = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.bFriday setBackgroundImage:[UIImage imageNamed:@"button_rechts_1"] forState:UIControlStateNormal];
    [self.bFriday setTitle:@"Freitag" forState:UIControlStateNormal];
    [self.bFriday setFrame:frameBtn5];
    [self.bFriday addTarget:self
                     action:@selector(friday:)
           forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:self.bFriday];






}

-(void)monday:(id)sender {

    UINavigationController *navController = (UINavigationController*) self.sidePanelController.centerPanel;

    MyTableController *myNewTableController = (MyTableController*)[navController.viewControllers objectAtIndex:0];
    myNewTableController.sDay = @"Montag";
    NSLog(@"%@",myNewTableController.sDay);

}

-(void)tuesday:(id)sender {

    UINavigationController *navController = (UINavigationController*) self.sidePanelController.centerPanel;

    MyTableController *myNewTableController = (MyTableController*)[navController.viewControllers objectAtIndex:0];
    myNewTableController.sDay = @"Dienstag";
    NSLog(@"%@",myNewTableController.sDay);


}
-(void)wendsday:(id)sender {

    UINavigationController *navController = (UINavigationController*) self.sidePanelController.centerPanel;

    MyTableController *myNewTableController = (MyTableController*)[navController.viewControllers objectAtIndex:0];
    myNewTableController.sDay = @"Mittwoch";
    NSLog(@"%@",myNewTableController.sDay);


}
-(void)thursday:(id)sender {

    UINavigationController *navController = (UINavigationController*) self.sidePanelController.centerPanel;

    MyTableController *myNewTableController = (MyTableController*)[navController.viewControllers objectAtIndex:0];
    myNewTableController.sDay = @"Donnerstag";
    NSLog(@"%@",myNewTableController.sDay);


}
-(void)friday:(id)sender {

    UINavigationController *navController = (UINavigationController*) self.sidePanelController.centerPanel;

    MyTableController *myNewTableController = (MyTableController*)[navController.viewControllers objectAtIndex:0];
    myNewTableController.sDay = @"Freitag";
    NSLog(@"%@",myNewTableController.sDay);


}

现在的问题是PFQueryUITableView没有显示新parseClass的内容,有没有人知道为什么? 非常感谢!

1 个答案:

答案 0 :(得分:0)

monday ... friday方法中,您设置的是sDay,但您没有更改parseClassName中存储的值。解决这个问题的一种方法是在每个方法中添加以下内容

myNewTableController.parseClassName = @"SOME VALUE";

另一种选择是自定义sDay的setter,以便更新parseClassName代码如下所示

- (void)setSDay:(NSString *)sDay
{
    if (![_sDay isEqualToString:sDay]) {
        _sDay = sDay;
        self.parseClassName = sDay;
    }
}