How can I use PFQueryViewController as a subview of UITableViewController?

邮差的信 提交于 2019-12-13 06:15:45

问题


I’m trying to build a group messaging app with Parse. I would like to use storyboards only because I am new to iOS.

  • The first screen is a UITableViewController with a list of groups.
  • The second screen is a PFQueryTableViewController that inherits from UITableViewController with a list of messages for that group.

I would like to add a chat box(UITextField) to the PFQueryViewController, but I can’t seem to do that because it is a UITableViewController.

From what I can tell in order to add a chat box I need to use a UIViewController and manually add a table view. Then resize the table view to allow for a chat box at the bottom.

The problem is then PFQueryViewController inherits from a UITableViewController and not a UITableView.

I am using this to pass the selected group PFObject to the new PFQueryViewController.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    [self performSegueWithIdentifier:@"detail" sender:nil];

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    if([[segue identifier] isEqualToString:@"detail"])
    {
        NSIndexPath *ip = [self.tableView indexPathForSelectedRow];
        PFObject *passObj = [self.objects objectAtIndex:ip.row];
        PFQueryTableViewController *messageDetail=[segue destinationViewController];
        [messageDetail setReceiveObj:passObj];
        messageDetail.hidesBottomBarWhenPushed = YES; //Hide Tab Bar
    }

How can I use PFQueryViewController as a subview of UIViewController and pass the PFObject to that controller?

*I don't have enough reputation for images


回答1:


I'm, unfamiliar with the Parse framework but you should be able to use View Controller Containment to achieve this.

Here is a nice guide to check out.

Here is the relevant part for adding the view of a view controller as a subview in another view controller:

// put this in viewDidLoad
[self addChildViewController:_pfQueryController];               //  1
[self.view addSubview:_pfQueryController.view];                 //  2
[_pfQueryController didMoveToParentViewController:self];        //  3


来源:https://stackoverflow.com/questions/22640757/how-can-i-use-pfqueryviewcontroller-as-a-subview-of-uitableviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!