Note that there are some explanatory texts on larger screens.

plurals
  1. POCalling delegate method from popover class
    primarykey
    data
    text
    <p>I'm new to Objective C and I'm having trouble getting delegates to work in my code.</p> <p>I have a class called cViewController and in this class has a UIWebView to fetch webpages and a button above it that calls a popover class called prodMenu. What I'm having trouble with is that the function to call webpages from the prodMenu class and display it on the parent UIWebView isn't working.</p> <p><strong>cViewController.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import "prodMenu.h" @interface cViewController : UIViewController &lt;prodMenuDelegate&gt;{ UIPopoverController *cpopover; IBOutlet UIWebView *webImageDisplay; } @property (nonatomic, retain) UIWebView *webImageDisplay; @property (nonatomic, retain) UIPopoverController *cpopover; - (IBAction)cPopoverTapped:(id)sender; - (void) fetchWebsite:(NSString *)website; //This is the delegate method I'm trying to call in the popover class. @end </code></pre> <p><strong>cViewController.m</strong></p> <pre><code>- (IBAction)cPopoverTapped:(id)sender { prodMenu *tp = [[prodMenu alloc] init]; cpopover = [[UIPopoverController alloc] initWithContentViewController:tp]; [tp release]; CGRect rect = CGRectMake(40, 0, 50, 50); cpopover.popoverContentSize = CGSizeMake(250, 225); [cpopover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; } - (void)fetchWebsite:(NSString*)website{ //This function is called by prodMenu class NSLog(@"address: %@", website); NSString *urlAddress = website; NSURL *url = [NSURL URLWithString:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [webImageDisplay loadRequest:requestObj]; [webImageDisplay release]; } - (void)viewDidLoad { [self fetchWebsite:@"http://www.yahoo.com"]; [super viewDidLoad]; } </code></pre> <p><strong>prodMenu.h</strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @protocol prodMenuDelegate; @interface prodMenu : UIViewController{ &lt;prodMenuDelegate&gt; delegate; } - (IBAction)radBtn:(id)sender; //This is the IBAction that calls the fetchWebsite function @property (nonatomic, assign) id &lt;prodMenuDelegate&gt; delegate; @end @protocol prodMenuDelegate - (void)fetchWebsite:(NSString *)website; @end </code></pre> <p><strong>prodMenu.m</strong></p> <pre><code>#import "prodMenu.h" #import "cViewController.h" @implementation prodMenu @synthesize delegate; - (IBAction)radBtn:(id)sender{ [delegate fetchWebsite:@"http://www.google.com"]; //Here is the call to the method } </code></pre> <p>Am I missing something here to call the delegate method? There aren't any errors or warnings. All I want to do is when the user presses a button on the popover view, the parent class underneath changes the webpage. Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload