Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

guydor

macrumors member
Original poster
Mar 10, 2009
67
0
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!
 
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.
 
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.

So I didn't understand you, can you give me an example of a "define" for a UIVIewController?
 
Did you mean searchbar or searchBar in this declaration?

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!
 
So I didn't understand you, can you give me an example of a "define" for a UIVIewController?
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
 
Now I understand you, thanks

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


Well, I don't have any define for my UIViewControllers
Thanks
 
Well, I don't have any define for my UIViewControllers
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".
 
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;
 
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?
 
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?

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...
 
No, still the same error:

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

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.
 
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.
 
I'm almost certain the problem is that they're trying to reference searchBar.text, where searchBar is an object of type firstUIViewController (which has no text property) and not UISearchBar (which does), but the OP has been less than forthcoming.

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.