如何使用pushViewController和popViewController

时间:2012-11-27 10:32:02

标签: iphone xcode

我想要一个viewcontroller切换另一个B viewcontroller,第一次,我按(按GuestBook按钮)和TableView获取信息确定,然后按回按钮ok,再次按下(按GuestBook按钮),JSON数据NSLog有消息,但没有出现tableview数据! 会发生什么事?

PS:我使用故事板!有一个自定义单元格xib!

A.M

- (IBAction)toHostGuestBook:(id)sender {
    hgbvc = [self.storyboard instantiateViewControllerWithIdentifier:@"ToHostGuestBookSegue"];
    hgbvc.eventidStr = eventidStr;
    NSLog(@"hgbvc.eventidStr:%@",hgbvc.eventidStr);
    [self.navigationController pushViewController:hgbvc animated:YES];

}

B.m

- (IBAction)backToHostMainEventDetail:(id)sender {
    [self.navigationController popViewControllerAnimated:YES]; 
}

B.m

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *GuestBookCellIdentifier = @"GuestBookCellIdentifier";

    static BOOL nibsRegistered = NO;
    if (!nibsRegistered) {
        UINib *nib = [UINib nibWithNibName:@"GuestBookCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:GuestBookCellIdentifier];
        nibsRegistered = YES;
    }

    gbcell = [tableView dequeueReusableCellWithIdentifier:GuestBookCellIdentifier];
    if (gbcell == nil) {
        gbcell = [[GuestBookCell alloc]
                   initWithStyle:UITableViewCellStyleDefault
                   reuseIdentifier:GuestBookCellIdentifier];
    }

    NSDictionary *dict = [messageRows objectAtIndex: indexPath.row];

    gbcell.nicknameStr = [dict objectForKey:@"vusr"];
    gbcell.dateStr = [dict objectForKey:@"date"];
    gbcell.messageStr = [dict objectForKey:@"message"];


    return gbcell;

}

3 个答案:

答案 0 :(得分:0)

添加此内容并尝试

-(void)viewWillAppear:(BOOL)animated

{

[super viewWillAppear:animated];

[self.tableView reloadData]; //your table view name

}

答案 1 :(得分:0)

hgbvc B控制器由A控制器保留。因此,当B控制器跳出来时它不会释放。当B控制器再次按下时,未调用viewDidLoad方法。

解决方案:提取tableview加载数据方法。按B时调用此方法。

B控制器中的

- (void)showDataWithEventId:(NSString *)eventId
{
    //retrive data 
    //table view reload
}

答案 2 :(得分:0)

尝试在popViewController的代码下面重新加载表视图数据这是你想要的工作