Can't get the methods at interface builder - iphone

I declared one method in sample.h and implemented in sample.m . Now i want to perform one action through connecting to a button and that method. but the files owner doesn't show any of my methods. Whats the problem.. Can anyone help me. i am new to this.
Thanks in Advance.

Have you specified that the File's Owner is of type sample? You can do that on the Identity tab in Interface Builder.
If sample is not a subclass of UIViewController you would most likely add an NSObject in Interface Builder and then set the Type to sample. You would also most likely have to add an IBOutlet to your view controller/File's Owner of type sample and connect it to the sample object in IB.

You want to make a function called on button press event.
so declare method in .h file as
-(IBAction) click:(id)sender
then it shows in file's owner inspector.Make connection with button for touchUpInside.

Related

How to My own textField and add a redirection method in it

I am having a situation where I have to create a a subclass of textField so that when object to this subclass is used in any viewcontroller and user clicks to it to write something then user will automatically redirected to some other class.
Let me explain with the help of an example :
suppose MyTextField is a subclass if UITextField
when and when object of MyTextField is created in any ViewController1 and user will try to click on that(object of MyTextField) the application will automatically redirected to a new view controller.
Please note that I don't want to use the Delegate method of the UITextField in the ViewController1.
Is it possible ?
Please reply if you have any alternate
thank you
As UITextField is inherited from UIResponder, you can use –canBecomeFirstResponder and -becomeFirstResponder methods in your inherited class.
As per my understanding, you may have a need to display some text/placeholder in textfield. When a user click on textfield you are navigating to some other class. If i am correct, then why don't you use a button instead of a UITextfield as you are not interested to call the delegate methods of TextField. You can set some delegates which will handle your actions simply.

reference to UITextField not working?

I have created a controller class in which I have created a outlet to UITextfield. But The problem is that I am unable to get reference in the controller class, so unable to call any of textfield methods. The reference is returning null.
I have defined outlet (and connected them) properly to the text field in class but still not able to find the error.I am clean bowled !!
<UITextFieldDelegate>
Did you added this delegate into .h file of your ViewController? Which is required to used its methods?
Have You Adopted
"UITextFieldDelegate" Protocol in your "ViewController.h"..?.
If Not You need to Add that protocol inside the "< >" of your "ViewController.h".
UITextFieldDelegate protocol contains various Method Declaration which called during the Various Event(begin text Editing,ended text Editing,).
For detail Information go Through this Link.

to connect button outlet to file owner programmatically

I have created the outlet and property. Now can One please help me how can I connect outlet to file owner programmatically by giving some example or tutorial.Thnks in Advance.
Following is my outlet.
IBOutlet UIButton *btnStatus;
#property(nonatomic ,retain)IBOutlet UIButton *btnStatus;
IBOutlet is not at all special. In fact, it's just a macro that evaluates to nothing. It is just a signal to Interface Builder when it reads the source file. Just set it to whatever object you want, as you would with any property assignment.
Take a look at http://www.cocoadev.com/index.pl?NSButton (in general a fairly useful site) for examples.

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;

Arbitrary objects to handle actions?

My question may be a bit stupid, but why can't any object instantiated in IB handle, say, button click? I mean I'm able to add my own object to a xib, and link outlets to cotrols and control actions to object's method, but once I press the button everything just crashes (uknown selector).
Do you guys have a hint around that?
EDIT: The code, as requested:
#interface TextController {
IBOutlet UILabel * textLabel;
IBOutlet UITextField * textField;
}
-(IBAction)buttonClicked:(id)sender;
#end
#implementation TextController
-(IBAction)buttonClicked:(id)sender {
textLabel.text = #"Ololo";
}
#end
Connections in IB are ok, just believe me. It's really hard to get them wrong with all this drag'n'drop stuff :)
EDIT 2: TextController is not a file owner (in this case it works fine). However, I just want to understand why I can't wire up an action to some object (may be even not a subclass of UIViewController).
You can wire outlets and actions to any object in the nib-file. Drag an NSObject form the library palette onto your nib-file, in Interface Builder. Then go to the Identity tab of the information palette and set the Class of your object.
This way you can instantiate any object of any class from your nib. If the target you want to hook to is statically created from the nib-file. Make sure that the file's owner have at least one reference to your object, or else it will be deallocated as soon as it has been created. Targets are not retained by the sender.
If the object you want to hook up should not be statically created from your nib, then implement awakeFromNib in a class that is instantiated from the nib-file and hook up the targets in code.
Last option is if you do not have any sub-class of your own in the nib-file at all. Then implement initWithNibName:bundle: in your UIViewController subclass, and hook up your targets in code after calling the super implementation.
post code, this usually means you dont have your connections wired up correctly. Is file's owner TextController in IB?