Need help with inheritance in UIViewController subclass

Discussion in 'iOS Programming' started by guydor, May 17, 2010.

  1. guydor macrumors member

    Joined:
    Mar 10, 2009
    #1
    Hi,

    I have an UIWebView in my A view controller for example.
    I want to use this UIWebView in my B view controller subclass, for some reason I get this error:
    "request for member 'request' in something not a structure or union"

    Here is my code:

    mainViewController .h (which called A view controller)
    Code:
    
    @interface mainViewController : UIViewController <MFMailComposeViewControllerDelegate> {
    UIWebView *leftWebView;
    UIWebView *rightWebView;
    }
    
    
    @property (nonatomic, retain) IBOutlet UIWebView *leftWebView;
    @property (nonatomic, retain) IBOutlet UIWebView *rightWebView;
    
    @end
    
    and of course @synthesize for both of them.

    Here is my scondViewController .h (which called B view controller
    Code:
    
    @class mainViewController;
    @interface rightSharingViewController : UIViewController {
    	
    	NSString *leftWebViewUrl;
    	NSString *rightWebViewUrl;
    	mainViewController *leftWebView;
    	mainViewController *rightWebView;
    }
    
    @property (retain) NSString *leftWebViewUrl;
    @property (retain) NSString *rightWebViewUrl;
    @property (retain) mainViewController *leftWebView;
    @property (retain) mainViewController *rightWebView;
    
    - (void)doneButton:(id)sender;
    - (void)safariButton:(id)sender;
    - (void)mailButton:(id)sender;
    
    - (void)leftLaunchMailAppOnDevice;
    - (void)rightLaunchMailAppOnDevice;
    - (void)displayLeftComposerSheet;
    - (void)displayRightComposerSheet;
    	
    
    @end
    
    
    .m scondViewController

    Code:
    #import "rightSharingViewController.h"
    #import "mainViewController.h"
    
    
    @implementation rightSharingViewController
    @synthesize leftWebViewUrl;
    @synthesize rightWebViewUrl;
    @synthesize leftWebView;
    @synthesize rightWebView;
    
    
    
    /*
     // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
     - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
     if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
     // Custom initialization
     }
     return self;
     }
     */
    
    /*
     // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
     - (void)viewDidLoad {
     [super viewDidLoad];
     }
     */
    
    
    - (void)doneButton:(id)sender {
    	[self dismissModalViewControllerAnimated:YES];
    }
    
    
    - (void)safariButton:(id)sender {
    	
    }
    
    
    - (void)mailButton:(id)sender {
    	Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
    	if (mailClass != nil)
    	{
    		if ([mailClass canSendMail])
    		{
    			
    			[self displayRightComposerSheet];
    		}
    		else {
    			[self rightLaunchMailAppOnDevice];
    		}
    		
    	}
    	else {
    		[self rightLaunchMailAppOnDevice];
    	}
    }
    
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        // Overriden to allow any orientation.
        return YES;
    }
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    #pragma mark -
    #pragma mark Compose Mail
    -(void)displayLeftComposerSheet {
    	MFMailComposeViewController *leftPicker = [[MFMailComposeViewController alloc] init];
    	leftPicker.mailComposeDelegate = self;
    	[leftPicker setSubject:@"A Website to Share With You"];
    	//mainViewController.leftWebView = leftWebView;
    	
    	leftWebViewUrl = leftWebView.request.URL.absoluteString;
    	
    	NSString *leftEmailBody = [[NSString alloc] initWithFormat:@"Hi, I would like to share with you this link: %@", leftWebViewUrl];
    	[leftPicker setMessageBody:leftEmailBody isHTML:NO];
    	[self presentModalViewController:leftPicker animated:YES];
    	[leftPicker release];
    }
    
    
    -(void)displayRightComposerSheet {
    	MFMailComposeViewController *rightPicker = [[MFMailComposeViewController alloc] init];
    	rightPicker.mailComposeDelegate = self;
    	[rightPicker setSubject:@"A Website to Share With You"];
    	
    	rightWebViewUrl = rightWebView.request.URL.absoluteString;
    	
    	NSString *rightEmailBody = [[NSString alloc] initWithFormat:@"Hi, I would like to share with you this link: %@", rightWebViewUrl];
    	[rightPicker setMessageBody:rightEmailBody isHTML:NO];
    	[self presentModalViewController:rightPicker animated:YES];
    	[rightPicker release];	
    }
    
    
    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {	
    	switch (result) {
    		case MFMailComposeResultCancelled:
    			break;
    		case MFMailComposeResultSaved:
    			break;
    		case MFMailComposeResultSent:
    			break;
    		case MFMailComposeResultFailed:
    			break;
    		default:
    			break;
    	}
    	
    	[self dismissModalViewControllerAnimated:YES];
    }
    
    
    -(void)leftLaunchMailAppOnDevice {
    	MFMailComposeViewController *leftPicker = [[MFMailComposeViewController alloc] init];
    	[leftPicker setSubject:@"A Website to Share With You!"];
    	
    	leftWebView.request.URL.absoluteString;
    	
    	NSString *emailBody = [[NSString alloc] initWithFormat:@"Hi, I would like to share with you this link: %@", leftWebViewUrl];
    	[leftPicker setMessageBody:emailBody isHTML:NO];
    	NSString *email = [NSString stringWithFormat:@"%@", emailBody];
    	email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
    }
    
    
    -(void)rightLaunchMailAppOnDevice {
    	MFMailComposeViewController *rightPicker = [[MFMailComposeViewController alloc] init];
    	[rightPicker setSubject:@"A Website to Share With You!"];
    	
    	rightWebView.request.URL.absoluteString;
    	
    	NSString *emailBody = [[NSString alloc] initWithFormat:@"Hi, I would like to share with you this link: %@", rightWebViewUrl];
    	[rightPicker setMessageBody:emailBody isHTML:NO];
    	NSString *email = [NSString stringWithFormat:@"%@", emailBody];
    	email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    	[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
    }
    
    
    
    
    - (void)didReceiveMemoryWarning {
        // Releases the view if it doesn't have a superview.
        [super didReceiveMemoryWarning];
        
        // Release any cached data, images, etc that aren't in use.
    }
    
    
    - (void)viewDidUnload {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
        // e.g. self.myOutlet = nil;
    }
    
    
    
    
    
    
    - (void)dealloc {
        [super dealloc];
    	
    	[leftWebViewUrl release];
    	[rightWebViewUrl release];
    	[leftWebView release];
    	[rightWebView release];
    	
    }
    
    @end
    
    


    Thanks!
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Where do you assign values to leftWebView and rightWebView?
     
  3. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #3
    First Thank you!

    Second, the UIWebViews get their values from a UISearchBar search word
    that display search results from Google and Yahoo!, I have made a string with the Google search url a assigned the search word to chained to the url.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    I'm afraid you don't understand my question. Where do you assign leftWebView and rightWebView to instances of UIWebView. This has nothing to do with their URLs or anything else within the webViews themselves.

    In other words, where do these ivars go from nil to non-nil values?
     
  5. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #5
    So I don't understand your question

    Can you give me a code example or anything else?

    Thank you for your patience!
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    If you don't understand the question, I suspect any code or help or anything else I give won't be understood either, since it's a pretty basic question. Therefore, I don't believe I can be of any further help. Sorry.
     
  7. ThomasPaul10 macrumors newbie

    Joined:
    Jun 11, 2008
    #7
    I haven't looked over the whole implementation of your second view controller but from the interface stand point I believe you are misunderstanding how to use inheritance.
    Inheritance works by using one class and extending that class by another. For example suppose you have ViewControllerA. Now if you want to inherit properties from ViewControllerA your would make a second class maybe called ViewControllerB and at the top of the interface it would look like ViewController B : ViewController A. This would allow you to access all the properties in ViewControllerA from ViewControllerB without declaring those properties again and as long as those properties are not private.
    I hope this makes since and answers your question.
     

Share This Page