Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8021135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:53:22+00:00 2026-06-04T21:53:22+00:00

EDIT 2: I tried pointing to the view controller using the following code: UIStoryboard

  • 0

EDIT 2: I tried pointing to the view controller using the following code:

UIStoryboard *iPadStoryboard = [UIStoryboard storyboardWithName:@”iPadStoryboard” bundle: nil];
GTGiftsIPadViewController *giftsIVC = (GTGiftsIPadViewController *)[iPadStoryboard instantiateViewControllerWithIdentifier: @”giftsTableViewControllerId”];
[giftsIVC setGiftsDelegate:self];
NSLog(@”%@”, giftsIVC);
NSLog(@”%@”, [[[[[[self parentViewController] parentViewController] childViewControllers] objectAtIndex:0] childViewControllers] objectAtIndex:0]);

However, this outputs:

2012-06-02 14:28:47.148 Gift Manager[3958:707] <GTGiftsIPadViewController: 0xc6b9980>
2012-06-02 14:28:47.152 Gift Manager[3958:707] <GTGiftsIPadViewController: 0xc6a16d0>

Meaning that giftsIVC is not pointing to the proper view controller. It has to point to the view controller given by [[[[[[self parentViewController] parentViewController] childViewControllers] objectAtIndex:0] childViewControllers] objectAtIndex:0]. However, I cannot use this code because it is does not work for both the portrait and landscape view.
This seems like something that should be very straight forward to do, but I’m pulling my hair out trying to figure this out! It’s driving me crazy!

EDIT: I figured out the problem and it has to do with how I’m setting the delegate. This is my (poor) way of setting the delegate:

[[[[[[[self parentViewController] parentViewController] childViewControllers] objectAtIndex:0] childViewControllers] objectAtIndex:0] setGiftsDelegate:self];

Basically [[[[[[[self parentViewController] parentViewController] childViewControllers] objectAtIndex:0] childViewControllers] objectAtIndex:0] is just referencing my table view controller. Is there an alternative way I could write this bit of code to exclude the [[[[[[[self parentViewController] parentViewController] childViewControllers] objectAtIndex:0] childViewControllers] objectAtIndex:0] portion?

I have been trying to avoid creating my own delegate protocols, mainly because I’m not very comfortable with the idea of a delegate yet. Anyway, I went ahead and created one yesterday because I really needed it, and to it worked very well! I have a split view controller that displays two controllers when the iPad is in landscape mode (one table view and a detail view for the objects in the table view). The purpose of the delegate protocol is to allow the table view to update the detail view when an object in the table view is selected. This works in landscape mode; however, in portrait mode I only have one view controller and a button to display a popover that presents the table view (this is almost identical to the Notes app on the iPad).

My problem is that when in portrait mode and a object in the popover view table is selected the didSelectGift method is not called; however, in landscape mode it is. See capitalized comments below.

This is my code for the delegate protocol:

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "GTAddIPadViewController.h"

@class GTGift, GTGiftCell;

@protocol GTGiftsIPadViewControllerDelegate;


@interface GTGiftsIPadViewController : UITableViewController

@property (nonatomic, assign) id <GTGiftsIPadViewControllerDelegate>giftsDelegate;
@property (nonatomic, strong) IBOutlet UITableView *giftsTable;

@end


@protocol GTGiftsIPadViewControllerDelegate <NSObject>

- (void)didSelectGift:(GTGift *)selectedGift;

@end

didSelectGift is called in the GTGiftsIPadViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    GTGift *gift = [[[GTGiftStore sharedStore] allGifts] objectAtIndex:[indexPath row]];
    [giftsDelegate didSelectGift:gift]; //THIS FUNCTION IS NOT CALLED (TESTED BY PUTTING AN NSLOG INSIDE IT)
    NSLog(@"%@", [gift name]); //THIS OUTPUTS PROPERLY THEREFORE TABLEVIEW:DIDSELECTROWATINDEXPATH: IS CALLED
}

The delegate is set the viewDidLoad method in a view controller called GTDetailIPadViewController

The didSelectGift method is implemented in the GTDetailIPadViewController:

- (void)didSelectGift:(GTGift *)selectedGift 
{
    [self setDetailGift:selectedGift];
    [self populateTable];
}

(populateTable is a method that uses the instance variable of detailGift and populates the detail view with these values)

I really cannot understand why it works perfectly when the table is presented in the split view but does not work when it is presented in the popover view. Any help would be really appreciated and I hope I have made my problem clear! Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:53:23+00:00Added an answer on June 4, 2026 at 9:53 pm

    So, this code:

    [[[[[[self parentViewController] parentViewController] childViewControllers] objectAtIndex:0] childViewControllers] objectAtIndex:0]
    

    to reference to your table view controller… that’s a bit crazy 🙂

    Also, I don’t think delegate is the way to go here..

    If you created a standard master/detail split view project in XCode, the master controller (the table view controller), should have a pointer to the DetailViewController (If I understand correctly, that would be the piece you call the delegate in your code).

    So instead of declaring any delegate, you would just point directly to that detailViewController.

    If for some reason, that pointer does not exist, you would want to create it, and whenever the master and detail are initialized, have something like this:

    MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
    DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
    masterViewController.detailViewController = detailViewController;
    

    (if your master and detail are not allocated in code like here, they should still both be accessible from a common place, let’s say the app delegate, as IBOUtlets, you would then just use the third line of code, after making sure you have a property ‘detailViewController’ in your master’s header)

    That way, you should have the detailViewController referenced from the master view controller at all time, so you can call any method on it from the table view controller(master)

    [detailViewController didSelectGift:selectedGift];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried the following: $.load(Views/chatBox.html).appendTo('body') Console Output: TypeError: $.load is not a function EDIT
Controller First I tried this: [HttpPost] public ActionResult Edit(JournalEntry journalentry) { if (ModelState.IsValid) {
I've tried multiple ways to edit Flash Objects / Embeds via Javascript and it
Does anyone know how can I edit a subitem on a listView? I've tried
When a user is using a Detailsview or Formview in Edit mode, and tries
EDIT: I am using MS SQL server 2008 R2 as well. Well, on a
I've been writing output from perl scripts to files for some time using code
I'm working on a simple note-taking/painting app. I have a view controller that works
As a precaution against hotlinking, I've been using the following rule to redirect people
EDIT : Ok, I found out why. My getX and getY were overriding the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.