问题
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