File's Owner didn't received Action - iphone

the ping1 and how1 below method didn't called from UIButton
so i was double checking it in xib what i am wrong.
but i can't found the problem.
to solve this only i can do is looking the xib and code
is there any know-how available to solve it?
something like insert some code when UIButton send event
anyone advice me it will be thankful
bonhyoung.
#interface ViewController : UIViewController
-(IBAction)ping1:(id)sender;
-(IBAction)how1:(id)sender;
#end
#implementation ViewController
-(IBAction)ping1:(id)sender
{
// i put the break point in here
}
-(IBAction)how1:(id)sender
{
// i put the break point in here
}
// some other code...
#end

You should connect some IBOutlets and check in viewDidLoad that your connections are right (ie that your IBOutlets are not nil once the view is loaded).

First make sure that the file owner's class is set to ViewController. This is in the IB pane, click on the File's Owner and select the 3rd tab on the right panel. It should say ViewController and not UIViewController.
Second make sure your actions are setup. Right click on the button, and make sure the Touch Up Inside is wired to the correct method.

Related

My objects in storyboard don't link correctly with the code

I am trying to use storyboards in my application. I began well, I have added two view controllers with a button to go from the first to the second.
The problem is in this second view controller: the objects I add on it and link with the code do not work. When I set a breakpoint in the view controller code, the 'self.property' is set to nil, whereas it should be instantiated by the storyboard.
I have been looking for an answer for hours, and I really don't understand the problem, since all the rest seems to be good.
I have tried to write the property in the code (strong/nonatomic, nonatomic/retain and even weak/nonatomic), to link the object directly to the code so that it creates the property automatically, but I never get anything else than "nil" with breakpoints.
viewController.h:
#interface NMLoadingViewController : UIViewController
{
__weak IBOutlet UIProgressView *imageProcessingProgressView;
}
#property (weak, nonatomic) IBOutlet UIProgressView *imageProcessingProgressView;
#end
.m:
#synthesize imageProcessingProgressView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Custom initialization
NSLog(#"INIT.");
}
(amont other lines of irrelevant code)
If I set the breakpoint to the "INIT." line, my imageProcessingProgressView is nil. I can't see a reason for that, I guess I have missed a very little detail...
(Note that I have tried this with other objects, like a UILabel, but it did not work either. Stranger, when I had two objects, one of them had an adress which was not nil, but still it was corrupted and did not show the right object.)
Edit: It was a lot of trouble for nothing... The problem is about the Variable View in XCode, which show my variable to "nil", whereas a log shows me a correct object...
Remove this...
{
__weak IBOutlet UIProgressView *imageProcessingProgressView;
}
...and make the property strong.
Change your log message to...
NSLog(#"INIT: %#", self.imageProcessingProgressView);
...and see if you still have a problem. If you do, then take another look at your storyboard connections.
Make sure NMLoadingViewController is the class on your viewController
First try out the answer by #Eric because I do believe that is the real issue.
Also, make sure that you are actually using the interface builder to hook the controls back to the view controller. This is done by dragging a line from the control back to the property of the view controller.

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!

Outlets and buttons ignored

My problem is that I cannot access any of the controls in a view defined using interface builder. This is the .h code for the Navigation bar (as an example):
#import <UIKit/UIKit.h>
#interface myController : UIViewController {
IBOutlet UINavigationBar *tTitle;
}
#property (nonatomic,retain) UINavigationBar *tTitle;
#end
The implementation (.m) is:
#import "myController.h"
#implementation myController
#synthesize tTitle;
- (void)dealloc {
[tTitle release];
[super dealloc];
}
- (void)viewDidLoad {
tTitle.topItem.title=#"This is my title";
}
In viewDidLoad tTitle (and my other outlets) are always 0x0. I have omitted the two text fields and the button for brevity.
This exact code works in another view in the app without issue. In IB I right click on the file owner icon and it shows my outlets correctly (and the single button action). Yet at run time - nada. I click the button and no response. The title is still the default title. I cannot set the text fields text property because the fields are all 0x0.
The view is linked to the view controller. As near as I can tell everything is identical between the two views that are doing the same thing. Obviously something is awry, but I can't figure it out. Any help would be appreciated.
Okay. I did the ROI and figured it would be easier to delete and recreate the view (one control at a time) in an attempt to see where it was going awry. The answer is the title bar title set worked from the get-go. I have no idea why the other class didn't work. But discretion is the better part of valor in this situation. The new class is working fine. Thanks for everyone's input.

Creating a new ViewController and xib for programmatic display (with addSubview)

I am writing a library to be used by developers for the iPhone (similar to the way that OpenFeint is implemented) and I am trying to create a ViewController with an associated XIB so that I can instantiate it in my code with
SplashScreenViewController *splashScreenViewController = [[SplashScreenViewController alloc] init];
UIWindow *topApplicationWindow = [self getTopWindow];
[topApplicationWindow addSubview:splashScreenViewController.view];
However, while this works with simple controls (UIButtons, etc), nothing shows up with my SplashScreenViewController. SplashScreenViewController is very simple:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface SplashScreenView : UIViewController {
}
#end
and the implementation is empty. In my View XIB (SplashScreenView.xib), I have tried setting the File's Owner's class to SplashScreenViewController which didn't work, then I tried it the way I've seen it done in OpenFeint which is to add a View Controller in IB and make the main UIView a child of it and make it of class SplashScreenViewController instead. That also does not work (does not display).
I'm wondering if anyone has a good idea for what I might be missing, or if someone can recommend a walkthrough for creating new ViewControllers the way that I'm attempting to.
Thanks!
Try 2 things :
Call initWithNibName not just init. Maybe the OpenFeint you were talking about were overriding the init to call initWithNibName , that's why you don't see it.
Set SplashScreenViewController as your file owner, and connect his view outlet to your
view in IB.
Hope it helps.
Instead of [splashScreenViewController alloc], try [SplashScreenViewController alloc]. I'm surprised you didn't get a compiler warning.

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?