Reputation: 410
I'm developing an Ipad app with a custom split view. In the master view I have a tableViewController. I add items in this one with an add button in the navigation bar. This button is linked (i work with storyboard) with a popover segue to an other tableViewController that contains a few cells to enter datas. A button “save” dismiss the popover view an add item in the list of the masterView. What I want to do next is link master view’s prototype cells to an other view to enable the user to edit the selected item. I want to link this view with a popover segue (just like with the add button) and there‘s where is the problème : I get an red issue from xcode : Couldn't compile connection: => anchorView => > .
This a sample of my code that works fine. I would like to do pretty the same when I tap on a cell for editing.
The masterSplitView table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"assetCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
// Configure the cell...
AssetModel *myAssetModel = [self.arrayAsset objectAtIndex:indexPath.row];
cell.textLabel.text = myAssetModel.name;
// cell.textLabel.text = @"test";
return cell;
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:@"addAssetSegue"]){
AddAssetTVC *addAssetTVC = segue.destinationViewController;
addAssetTVC.delegate = self;
UIStoryboardPopoverSegue* popoverSegue = (UIStoryboardPopoverSegue*)segue;
[addAssetTVC setPopoverController:[popoverSegue popoverController]];
}
}
- (void) theSaveButtonOnTheAddAssetTVCWasTapped:(AddAssetTVC *)controller{
[controller.navigationController popViewControllerAnimated:YES];
[self reloadCache];
[self.tableView reloadData];
[self viewDidLoad];
}
And the save method of the add view :
- (IBAction)save:(id)sender{
[popoverController dismissPopoverAnimated:YES];
NSLog(@"Telling the ADDASSET Delegate that Save was tapped on the AddAssetTVC");
{...unrevelant coredata methods}
[self.delegate theSaveButtonOnTheAddAssetTVCWasTapped:self];
}
Thanks you for reading,
Alexandre
Upvotes: 5
Views: 7403
Reputation: 691
Based on @Rich's answer but with PopoverPresentationController
and in Swift.
override func perform() {
let svc = self.sourceViewController as! yourSourceViewController
let pvc = self.destinationViewController as! yourPresentedViewController
// Present the view controller using the popover style
pvc.modalPresentationStyle = UIModalPresentationStyle.Popover
svc.presentViewController(pvc, animated: true, completion: nil)
// Get the popover presentation controller and configure it
let cell = svc.tableView.cellForRowAtIndexPath(svc.tableView.indexPathForSelectedRow!)
let presentationController = pvc.popoverPresentationController
presentationController!.permittedArrowDirections = .Any
presentationController!.sourceView = svc.tableView
presentationController!.sourceRect = cell!.frame
}
Upvotes: 0
Reputation: 41
I had the same problem. Solved it by using a custom segue. In the class's prepare
method:
UITableViewController
UIPopoverController
initialized with the destination controllerframe
as the CGRect
Here's some sample code:
UITableViewController *tvc = (UITableViewController *)self.sourceViewController;
DetailsViewController *details = (DetailsViewController *)self.destinationViewController;
UITableViewCell *cell = [tvc.tableView cellForRowAtIndexPath:[tvc.tableView indexPathForSelectedRow]];
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:details];
details.popoverController = pop;
CGSize size = CGSizeMake(640, 460);
pop.popoverContentSize = size;
[pop presentPopoverFromRect:cell.frame
inView:tvc.tableView
permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown
animated:YES];
Upvotes: 4
Reputation: 396
I have been able to do this with minimal coding. Try this:
Upvotes: 0