Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-29-2010, 04:40 PM   #1 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 5
aaronbastian is on a distinguished road
Default tying UISearch bar into an IBAction

Hi all,

To let you know from the beginning, I am a newbie at iPhone development, and I have taken an a monstrous task.

First of all, I am writing an application that allows to you to online shop. We have an affiliate account with a known online shopping website, are trying to tie our app into searching that site, and putting the results into a table, with hyperlinks to the site, etc.

But first problems first, one thing at a time:

In Interface Builder, I have a Search Bar, and an outlet connected to the search bar. I also have an IBAction made just to take the text that is entered into the search bar, storing it into a variable, and then searching this website (yes, that's a lot of stuff for an action).

Because I am so new at this process with IB, how do I connect the Search Bar with the IBAction? I know, stupid question.
aaronbastian is offline   Reply With Quote
Old 11-29-2010, 05:34 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

I'm assuming the IBAction method and the IBOutlet property (searchbar) are declared in the same class/viewcontroller. If so, simply use the name that you've given to the property.

For example, if you did

@property (nonatomic, retain) IBOutlet UISearchBar *searchBar;

within your method you can use, for example, [searchBar text] to get the text.
baja_yu is offline   Reply With Quote
Old 11-30-2010, 12:35 PM   #3 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 5
aaronbastian is on a distinguished road
Default

Thanks for the help, guys! I do think that I am still missing something rather crucial. I visited the iOS Application Programming guide, and this is what I have in the implementation file.

Code:
- (void)searchBar:(UISearchBar *)chetSearchBar SelectedScopeButtonIndexDidChange:(NSInteger)selectedScope{ }

- (BOOL)searchBar:(UISearchBar *)chetSearchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ }

- (void)searchBar:(UISearchBar *)chetSearchBar textDidChange:(NSString *)searchText{ }

- (void)searchBarBookmarkButtonClicked:(UISearchBar *)chetSearchBar{ }

- (void)searchBarCancelButtonClicked:(UISearchBar *)chetSearchBar{ }

- (void)searchBarResultsListButtonClicked:(UISearchBar *)chetSearchBar{ }

- (void)searchBarSearchButtonClicked:(UISearchBar *)chetSearchBar{ 
[[self navigationController] pushViewController:chetSearchResults animated:YES]; //load the Search Results for Chet in a new NIB file

}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)chetSearchBar{ }

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)chetSearchBar{ }

- (void)searchBarTextDidBeginEditing:(UISearchBar *)chetSearchBar{ }

- (void)searchBarTextDidEndEditing:(UISearchBar *)chetSearchBar{ }
Any insight?
aaronbastian is offline   Reply With Quote
Old 11-30-2010, 12:38 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Does your class (view controller) adopt the UISearchBarDelegate protocol in its declaration?
baja_yu is offline   Reply With Quote
Old 12-01-2010, 07:57 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 5
aaronbastian is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Does your class (view controller) adopt the UISearchBarDelegate protocol in its declaration?
I think so, but then again, I am not sure (too new).
In Interface Builder, connections tab on File's Owner, I have the following connections:

Outlets:
chetSearchBar - Search Bar
searchDisplayController - Search Display Controller
view - View
webResults - tableViewController
webView - Web View

Referenceing Outlets:
delegate - Search Display Controller
delegate - Search Bar
searchContentsController - Search Display Controller


But I am with you on it being something in IB, and something that is not connected correctly. I am just currently trying something simple, when the Search Button is clicked, load the next NIB file. That way, I'll know that I have the right code in the right method.

You've been a HUGE help so far! If you need any more information, please let me know! Thanks so much!
aaronbastian is offline   Reply With Quote
Old 12-01-2010, 08:31 AM   #6 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Check in the header file, where the @interface is declare, does it say UISearchBarDelegate within the angle brackets < >

For example:

@interface MyViewController : UIViewController <UISearchBarDelegate> {
baja_yu is offline   Reply With Quote
Old 12-02-2010, 08:15 AM   #7 (permalink)
Registered Member
 
Join Date: Nov 2010
Posts: 5
aaronbastian is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Check in the header file, where the @interface is declare, does it say UISearchBarDelegate within the angle brackets < >

For example:

@interface MyViewController : UIViewController <UISearchBarDelegate> {
Yes, I do have that exactly.
It's almost as if the send button on the firstResponder does nothing, or is not tied to the searchBarSearchButtonClicked method.

The only code that I have in that method currently is just pulling up a website in a new NIB, just to make sure that the button works.

I really hope that this thread doesn't frustrate you so much that you can't help. Thanks so much for your time!
aaronbastian is offline   Reply With Quote
Reply

Bookmarks

Tags
ibaction, uisearchbar, uiwebview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 377
7 members and 370 guests
daudrizek, HemiMG, Kirkout, MarkC, Sami Gh, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,665
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, daudrizek
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0