I want to have a UIView at the top half of my app, and a UITable at the bottom half. If I create a basic window application I can do this using IB. My main problem is that I seem to be only to do this in the delegate file which I would like to avoid.
I repeat the exact same steps I did in delegate in a separate controller and all I get is a blank screen.
0#interface RootViewController : UIWindow {
UIWindow *myWindow;
UIView *headerView;
UITableView *tableView;
}
#property (nonatomic, retain) IBOutlet UIView *headerView;
#property (nonatomic, retain) IBOutlet UITableView *tableView;
#property (nonatomic, retain) IBOutlet UIWindow *myWindow;
#end
I have each of these connect to the right view in rootviewcontroller.xib
I was wondering if anyone had any advice / snippets / examples I could use?
You need to use both the delegate file and Interface Builder. Interface Builder makes a view that binds to your delegate through IBOutlets and IBActions. I would run through several iPhone tutorials found on google before continuing.
Your RootViewController certainly shouldn't be a subclass of UIWindow. You probably want UIViewController for that.
Related
I have created a segmented control in the interface builder.
In my ViewController.h:
#interface ViewController : UIViewController <MKMapViewDelegate>
#property IBOutlet UISegmentedControl *Segment;
- (IBAction)switchMode:(id)sender;
#end
What I could do was to connect the Segmented Control with the IBAction but I cannot connect it with the IBOutlet!
Add a segmented control to the nib/Storyboard
Add the following code into the .h
#property(nonatomic,retain) IBOutlet UISegmentedControl *Segment;
In your storyboard or xib make sure that the files owner has the same classname as that of the class in which you written the outlet
Right click on the segmantControl and a window with outlets and actions appears
click and drag on the referencing outlet and drop it on the filesowner a new pop appears which includes your outlet written in code select it .
Connection established
you have forgotten to write parameters of property, correct it like below code
#property(nonatomic,retain) IBOutlet UISegmentedControl *Segment;
after this synthesize this property in .m file like this
#Synthesize Segment;
It appears that with some xCode update you can no longer connect certain outlets to your .h. You should be fine connecting it in your .m though:
#interface ViewController ()
#property (weak, nonatomic) IBOutlet UISegmentedControl *mySegmentedController;
#end
I will read some docs and see when this changed. Also there really is no reason to connect this property to your public interface (hence why it is no longer allowed). Only the View Controller of that class should have control over it.
I would like to understand the process of the declaration of a button.
#interface MerdaViewController : UIViewController{
IBOutlet UIButton *button;
}
#property (retain, nonatomic) IBOutlet UIButton *button;
#end
Why do we need those steps?
Is it always required?
Thank you so much.
Alex.
To create a button outlet you just need this line.
#property (retain, nonatomic) IBOutlet UIButton *button;
To create button action
-(IBAction)doSomething:(id)sender;
Just like to add another point:
Outlets should generally be weak/assign, except for those from File’s Owner to top-level objects in a nib file (or, in iOS, a storyboard scene) which should be strong/retain
at least in relatively new versions of XCode, you don't need to declare that instance variable. It's automatically taken care of.
you need the #property so you can call self.button and do whatever you like to it. IBOutlet tells XCode it's an element in your interface builder, so you can hook it up with that visual button you added to IB.
more often than not I find myself actually declaring an -(IBAction)buttonAction:(id)sender; rather than an IBOutlet. This way when you tap that button, the IBAction method is automatically triggered.
In xcode4.2, I have a UiViewController bundled with a same name xib file. In the UiViewController, I have some IBOutlets as below connect to the xib.
#property (retain, nonatomic) IBOutlet UIButton *topButton;
#property (retain, nonatomic) IBOutlet UIButton *hotButton;
#property (retain, nonatomic) IBOutlet UIButton *newButton;
#property (retain, nonatomic) IBOutlet UIButton *starredButton;
Now, I want to create a iPad version xib file of the UIViewController, what shall I do? i.e. how to connect one IBOutlet to two version's xib.
Any help will be appreciated! thanks advanced!
You just need two nibs with the appropriate naming
MyView~iphone.xib
MyView~ipad.xib
Then just make sure they both have the same file's owner and hook up the connections you want.
Go to New File -> Choose User Interface from left hand side -> Select Empty -> Select ipad in device Family drop down.
In xcode 4 we can't do that for a single xib,but we can create respective ipad versions all at once.Right click on target and click on duplicate.Then select "duplicate and transition to ipad".A new target and new set of xibs are created. This might help you.
I'm a newbie in iphone app developing, I just started learning two weeks ago due to the need of my final project.
So please forgive me if my question seems really stupid.
I've searched in forums and zbar documentation about how to customize the cameraView.
But I still didn't have a clear understanding about how to do it.
Now I'm trying to add tabbar into the cameraView, could anybody tell me how to do it?
I know that I need to use overlay and create my own view, adding the reader as a subview in it. Could anybody give me some direction more explicitly about how to reaise it?
Thanks in advance!!
You have to create your own custom UITabBarController class. And add this controller in your custom camera view. and custom camera view is created by the AVFoundation framework.
From what I know, you need to add the tabbar to the appDelegate and then inner views within each tab. Therefore you would have within the appdelegate applicationDidFinishLoading method
// Add the tab bar controller's view to the window and display.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
of course, you need to declare it in the appdelegate.h file
#interface AppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
Search for tabBar tutorials. They must be created BEFORE any NAVIGATION Controller.
Then place all your zbar code in the first view controller.
I am trying to figure out how to take a screen capture feed and send it to an iOS device (an iPad in this case) and have the images displayed on the screen, updating as each new image is sent while clearing the old one from memory.
I am just starting with the basics, so I am trying to get the simulator to load a screenshot from the desktop and display it on the screen, and then change the image as I take a new screenshot, and either delete the old one so I can rename the new screenshot to carry the same name or to simply overwrite the old one (thus the reference should still point correctly in the programming code).
I tried using a button that reloaded my UIImageView via:
- (IBAction)buttonPressed:(id)sender
{
[UIImageView setImage:ScreenCapture];
}
where ScreenCapture is the name of the UIImageView, with the hope that it would reload the existing referenced image.png file, but clicking the button simply exits that program within the simulator and goes back to the simulator's home screen.
Am I using the wrong object when trying to get this done via UIImageView? Is their an existing program/tutorial on this?
I would try to reverse engineer VNC for the iPhone, but both the copyright issues and the amount of advanced programming features are well beyond me.
Once I can get something working through Xcode, I am also planning on trying to implement the same thing via MonoTouch to see which language is easier to use and more beginner friendly.
Thank you for the help,
~Chris
header:
#import <UIKit/UIKit.h>
#interface Screen_Capture_3ViewController : UIViewController {
IBOutlet UIImageView *ScreenCapture;
IBOutlet UIBarButtonItem *Update;
}
#property (nonatomic, retain) IBOutlet UIImageView *ScreenCapture;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *Update;
- (IBAction)buttonPressed:(id)sender;
#end
.m:
#import "Screen_Capture_3ViewController.h"
#implementation Screen_Capture_3ViewController
#synthesize ScreenCapture;
#synthesize Update;
- (IBAction)buttonPressed:(id)sender
{
[UIImageView setImage:ScreenCapture];
}
Everything else remains at the default when selecting "View-based Application", and I connected the ScreenCapture to the UIImageView in Interface builder, as well as Update and buttonPressed to the UIBarButtonItem in Interface Builder.
setImage is an instance method, not a class method, so you can't send it directly to UIImageView (nor would it really mean much).
Keep your current code from your question for the header (but only the property should be marked as IBOutlet):
#interface Screen_Capture_3ViewController : UIViewController {
UIImageView *ScreenCapture;
UIBarButtonItem *Update;
}
#property (nonatomic, retain) IBOutlet UIImageView *ScreenCapture;
#property (nonatomic, retain) IBOutlet UIBarButtonItem *Update;
- (IBAction)buttonPressed:(id)sender;
#end
In your implementation, your event handler should be something like this:
- (IBAction)buttonPressed:(id)sender {
UIImage* newImage = [UIImage imageWithContentsOfFile:#"pathToImage.png"];
[ScreenCapture setImage:newImage];
}