How to connect a textfield and a Picker View - iphone

its the annoying noob again!
So I was trying to develop a small app to check files on a folder.
The text field is your search field.
You have a picker view with 3 options
Folder A
Folder B
Search on Google.
I've got a question:
1: How do I connect the search field and the pick that the user chose to a button so when the user clicks the button, lets say the button searches the users input on google?
I've made the application for 2 views.
One where the user inputs the information and the other to display that information.
My code is going something like this..
- (IBAction)buttonSearch:(id)sender {
self.userSearch = self.searchField.text; ///Users input on the search field
NSString *searchString = self.userSearch;
///I know Im missing the connection to the button with the pickView, how could I do that too?////
///Here should be something like go to google(or whatever choice the user made on pickview) and put the string on the search bar and hit search/// <---How do I do this too..? *****
}
#end
Thanks for the help, I know its a pain to answer such stupid questions.... :/
Have a nice day!

If you're using interface builder to create your view make sure to create IBOutlets for the textfields/pickers/etc. so that you can get their values.
#property (nonatomic, strong) IBOutlet UITextfield *myTextField;
Now in interface builder right click your text field and select "NewReferencingOutlet" and drag to "File's Owner" you should see "myTextField" as an option. Once that is attached you can then get the value of the text field like this.
self.myTextField.text
It will be similar for the pickerView except instead of UITextField you will use UIDatePIcker or something similar...
Hope that helps ;)

Related

How can I create notifications on UIButton

I am newbie at iOS programming. I want to put notifications on UIbutton (for example displaying the click count on top of its corner), shortly it informs some counting on UIButton.
Is it possible? Please give some ideas or some short code for how can I do it.
in the header file add
{
IBOutlet UIButton *counterbutton;
}
-(IBAction)pushed:(id)sender;
in the .m file
int count;
-(IBAction)pushed:(id)sender
{
count = count + 1;
counterbutton.text = [NSString stringWithFormat:#"count is %i",count];
}
In the interface builder connect the button to the view controller for both the IBAction and IBOutlet.
Flex_Addicted share that link in my question i guess sharing in here more discernible. In that example shows exactly what i asked and it is really easy do just add h and m files in your project. How can I add a badge to a standard UIButton?

Xcode iPhone - Class that asks for multiple text inputs and then returns them

I wan't to creata a "CatchNames" class which I can import into a view Controller that shows a text which asks for text input. I would like to be able to add an instance of CatchNames to my view, have it ask the user for three names in a row and return them in an array.
[self.view addSubview:[catchNames view]];
NSArray *myNamesArray = [catchNames namesArray];
The best way would be to have the application freeze kind of the way it does when you are prompted to enter a password in iOS and continue when the user entered 3 names so I can immediately catch the array in the next line.
While this might not be the best description I still hope you understand my problem.
How can I approach this?
Thank you in advance
I guess you appear to be looking to implement a simple form which gets the user input, retrieves and stores it in an array? Hopefully I haven't misunderstood the question, but this seems to be a simple task you can accomplish with one or more UITextField's and a UIButton as a 'Add' or 'Done' call to action.
Are you looking for some general UI coding level help regarding implementing such a view? If so, I would encourage taking a look at the XCode documentations of UITextField (for capturing text), UIButton (for handling actions) and UIView (for view hierarchy and animation implementation).
Some quick notes;
Looks like 3 names are compulsory, so, you may verify whether a UITextField is empty at the button's click action.
Have the array declared in the view controller, not the view
The 'freezing' you require should take care of itself as long as the view offers no other way out for the user other than clicking the button.
Do excuse me if I am oversimplifying the problem. Let me know if you need me to drill down into anything further.
Cheers!

Connecting an IBOutlet to a view within a scrollview within a tab view crashes app. Any ideas?

I used the tabview setup to create an app that has several tabs. One tab has a UIScrollView on it which loads 12 different views into 12 pages. I tried adding a button and imageview to one of the views and now it crashes. I've pored over every single question on here I can find, and have tried every suggested solution, but to no avail. The error that I get is the famous "this class is not key value coding-compliant for the key foo" error. As with everyone else who had this problem, if I disconnect the outlet, it works fine. I've checked and rechecked the class for the nib and it points to the right place.
So I'm not even sure where to go next.
I could post some code, but I don't even know what code would be helpful to post. I'm hoping someone just says, "Um yeah, you can't have a scroll view with multiple views in it and expect to have functionality on each page." That would be helpful!
Page2.h:
#import <UIKit/UIKit.h>
#interface Page2 : UIViewController {
IBOutlet UIImageView *infoImage;
}
#property (retain, nonatomic) UIImageView *infoImage;
(IBAction) showInfo:(id)sender;
#end
Page2.m:
- (IBAction)showInfo:(id)sender {
// do something please!
}
Then in the nib file I CTRL-dragged from "touch-up inside" on my button to the Files Owner and chose "showInfo" ... and I CTRL-dragged from Files Owner down to my UIImageView and chose infoImage.
CRASH
I am not cool enough to insert an image: http://i.stack.imgur.com/KjWhk.png
You still have an outlet connected in your nib that you no longer have defined in your class. You'll see in the inspector that it has turned gray. Disconnect it, and the error should be gone.
are u able to create any other outlet in the same Nib file, as i used to get the same crash, and it got fixed only when i duplicated the same nib, i had implemented almost all methods to solve it. If i am not wrong , this link can help you out https://discussions.apple.com/thread/2431110?start=0&tstart=0
I have sent you the email and attached your project. Hope its working at your end now.
Happy Coding!

iphone uitableview - linking problems?

I am trying to follow a tutorial about xml parsing http://www.edumobile.org/iphone/iphone-programming-tutorials/parsing-an-xml-file/ . The tutorial does not explain how to link and that is the part that i am stuck on. Looking at the source code provided i can see that "view" is linked with "file owner". In MY file, when i do this, i cannot link them. It does not highlight. Does anyone know why? what are the usual causes for this? (new to iphone). Thanks for any help!
You will find this helpful http://mobiforge.com/developing/story/iphone-programming-fundamentals-outlets-and-actions
This one is specific to XCode4 but is also helpful to understand the Interface Builder basics
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iPhone101/Articles/04_InspectingNib.html
If you add a new file (a subclass of view controller) you will get three files .h,.m and .xib. The File owner is always connected to the correct View Controller which happens to the owner of this nib(.xib) file. you can verify the same as shown in image below.
If this is the case then I am sure you can always link up your new elements (labels,buttons) to the correct Outlet. Just a reminder here that the declaration should start with the keyword IBOutlet so that It shows up in the interface builder.
eq IBOutlet UILabel *lblTitle;

UIButton Much needed IBOutlet?

I created a ViewController and it has 6 UIButtons.Each one has different tasks . Its work fine.
When i am creating one button (sample)
IBOutlet UIButton *loginnextbtn;
#property(nonatomic,retain) UIButton *loginnextbtn;
#synthesize loginnextbtn;
[loginnextbtn release];
-(IBAction)LoginNextBtnPressed:(id)sender;
then i delete these all IBOutlet ,property,synthesize,release .
I only added
-(IBAction)LoginNextBtnPressed:(id)sender;
Its work fine.My doubt is why we need to iboutlet for button.And also one important think is I dont change button title or image at anytime.I just use these buttons only for button click event .For this case can i use IBAction only ? Is there any problem occurs in my project while its running ..plz help me..
sorry for my bad english..
hey dragon there wont be any problem if u just use the IBAction for binding ur method with the button... If you are not changing the title or color of the button at run time then you dont need to take it as iboutlet... Just bind the button you took with the action you want to set for that particular button's click event...
Happy coding