request for member 'text' in something not a structure or unioun

Discussion in 'iOS Programming' started by guydor, Mar 1, 2010.

  1. guydor macrumors member

    Joined:
    Mar 10, 2009
    #1
    Hi,

    I have in my first UIViewController an UISearchBar.
    I want the value of the UISearchBar in my second UIViewController.
    Here is the code of the second UIViewController:

    firstViewController:
    .h file
    Code:
    UISearchBar *searchbar;
    
    @property (nonatomic, retain) IBOutlet UISearchBar *searchBar;
    
    .m file
    Code:
    @synthesize searchBar;
    
    - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
    	
    	[self dismissModalViewControllerAnimated:YES];
    	[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:
    					@"http://www.%@.com/", searchBar.text]]]];
    }
    
    


    secondViewController:
    .h file
    Code:
    firstUIViewController *searchBar;
    ...
    @property (nonatomic, retain) firstUIViewController * searchBar;
    
    .m file
    Code:
    
    @synthesize searchBar;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    	
    	NSString *urlAddress = [NSString stringWithFormat:@"http://www.%@.com/", searchBar.text];
    	NSURL *url = [NSURL URLWithString:urlAddress];
    	NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    	[webView loadRequest:requestObj];
    
    }
    
    I'm always get this error:
    "request for member 'text' in something not a structure or union"


    What should I do?
    Thanks!
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    It will be hard for us to determine what's wrong exactly without knowing how firstUIViewController is defined.
     
  3. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #3
    You still haven't told us how firstUIViewController is defined. Try giving us the complete .h and .m of the class so that we can see what the superclass is.

    Anyways, basically that error message is telling you that neither firstUIViewController nor any of its ancestor classes has a text property.
     
  4. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #4
    So I didn't understand you, can you give me an example of a "define" for a UIVIewController?
     
  5. Gepper macrumors member

    Joined:
    Dec 7, 2009
    #5
    Did you mean searchbar or searchBar in this declaration?
     
  6. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #6
    I sorry about the lowercase and the uppercase letter, because I changed it when I pasted the code here because these aren't the original variables names


    Thanks!
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Code:
    //
    //  UntitledViewController.h
    //  Untitled
    //
    //  Created by dejo on 3/2/10.
    //  Copyright DEJOware 2010. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface UntitledViewController : UIViewController {
    
    }
    
    @end
    
     
  8. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #8
    Now I understand you, thanks


    Well, I don't have any define for my UIViewControllers
    Thanks
     
  9. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    Huh, what? How does your code know what firstUIViewController is then? You edited your original post to include the code for "firstViewController: .h file". So, just paste the text of that entire file into a code block here. Also, might as well do the same for "secondViewController: .h file".
     
  10. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #10
    Here is my code:

    firstViewController
    .h file
    Code:
    @interface googleViewController : UIViewController {
    	UISearchBar *userSearch;
    }
    @property (nonatomic, retain) IBOutlet UISearchBar *userSearch;
    
    secondViewController
    .h file
    Code:
    @interface yahooViewController : UIViewController {	
    	googleViewController *googleUserSearch;	
    }
    
    @property (nonatomic, retain) googleViewController *googleUserSearch;
    
    
     
  11. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #11
    And you're still getting the "request for member 'text' in something not a structure or union" error? If so, is this coming from your viewDidLoad method?
     
  12. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #12
    I don't think so the problem is in the viewDidLoad because I have tried to use it in different methods and still the same error...
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    And in all these methods where the error occurs, is searchBar an object of type firstUIViewController?
     
  14. guydor thread starter macrumors member

    Joined:
    Mar 10, 2009
    #14
    No, still the same error:

    request for member 'text' in something not a structure or unioun
     
  15. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
  16. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #16
    Please post a complete set of compilable code (.h and .m files), so someone else can compile it and see the problem actually happen.

    Don't change any of the variable names, like you said you did in post #6 above. That creates new bugs that don't really exist in your original code.

    It's not possible to diagnose the exact problem without seeing all the code that makes up the exact problem. Posting fragments isn't enough.
     
  17. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #17
    I'm almost certain the problem is that they're trying to reference googleUserSearch.text, where googleUserSearch is an object of type googleViewController (which has no text property) and not UISearchBar (which does), but the OP has been less than forthcoming.
     
  18. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #18
    It doesn't help that he changes the names of everything.

    First, there is no class named firstUIViewController or secondUIViewController. The actual class names are googleViewController (firstUIViewController) and yahooViewController (secondUIViewController).

    Second, there is no searchBar instance variable. There is a parameter named searchBar in the searchBarSearchButtonClicked: method, but that doesn't seem to be the method with the error.

    Third, there is a userSearch ivar and property in googleViewController, but not in yahooViewController. Instead, yahooViewController has an ivar and property of type googleViewController. That is, it uses a has-a relationship (containment), not an is-a relationship (inheritance).

    Unfortunately, this is all from piecing together all the fragments, some of them renamed and some not, so it's entirely possible I've made an error in the repiecing together.
     
  19. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #19
    You got that right!

    True. I will amend my post accordingly. Sorry.
     

Share This Page