I'm trying to create an app that creates a random image button, and the code works. when my app generates an image, I'd like to create a button from which i can send an email with the screenshot attached...i know the codes for both actions, but when i put them in the controller h and m I've many errors...please help me!
#interface __3_ProductionsViewController : UIViewController
<MFMailComposeViewControllerDelegate>
-(IBAction)openMail:(id)sender;
-(IBAction)randomimagebutton;
{
IBOutlet UIImageView *imageview;
}
#end
Depending on the errors you are getting you might want to rearrange your formatting a little. This is how I would declare the h and m.
// __3_ProductionsViewController.h
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#interface __3_ProductionsViewController : UIViewController
<MFMailComposeViewControllerDelegate>
#property (nonatomic, retain) IBOutlet UIImageView *imageview;
-(IBAction)openMail:(id)sender;
-(IBAction)randomimagebutton:(id)sender;
#end
// __3_ProductionsViewController.m
#import "__3_ProductionsViewController.h"
#implementation UpdateViewController
#synthesize imageView;
-(IBAction)openMail:(id)sender {
}
-(IBAction)randomimagebutton:(id)sender {
}
#end
You'll need to connect the IBActions using interface builder as well as drag a connection to your imageView
Related
I am having a very difficult time switching between forms in Cocoa interfaces. From my initial form and its delegate, I can hide the initial window then load and display the second window with all properties on it. This is working working... Alas, on attempting to return to the initial window, I hide the second window and the initial does not return...
Here are my .h and .m for initial form and for formTwo...
.h
#import <Cocoa/Cocoa.h>
#class frmTwoDelegate;
#interface AppDelegate : NSObject {
#private
frmTwoDelegate *_frmTwo;
}
#property (assign) IBOutlet NSWindow *window;
- (IBAction)BtnSwitchAction:(id)sender;
#end
.m
#import "AppDelegate.h"
#import "frmTwoDelegate.h"
#implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
...
}
- (IBAction)BtnSwitchAction:(id)sender {
if (!_frmTwo) {
_frmTwo = [[DecriptDelegate alloc] initWithWindowNibName:#"frmTwo"];
[_frmTwo setFrmStart:self];
}
[_frmTwo showWindow:sender];
[_window setIsVisible:NO];
}
#end
Here are .h and .m for frmTwo
.h
#import <Cocoa/Cocoa.h>
#class AppDelegate;
#interface frmTwo : NSWindowController{
#private
AppDelegate *frmStart;
__unsafe_unretained NSTextView *_TxtView;
}
#property (retain) AppDelegate *frmStart;
#property (assign) IBOutlet NSWindow *frmTwo;
#property (unsafe_unretained) IBOutlet NSTextView *TxtView;
- (IBAction)BtnOpenActionPreformed:(id)sender;
- (IBAction)BtnBackActionPreformed:(id)sender;
#end
.m
#import "frmTwo.h"
#import "AppDelegate.h"
#implementation frmTwo
#synthesize frmStart;
- (id)initWithWindow:(NSWindow *)window
{
...
}
- (void)windowDidLoad
{
...
}
- (IBAction)BtnOpenActionPreformed:(id)sender
{
...
}
- (IBAction)BtnBackActionPreformed:(id)sender {
[frmStart ShowWindow];
[_frmTwo setIsVisible:NO];
}
#end
Here's a simpler way to achieve what you are doing. I'm not going to write the .h definitions, just infer what the variables represent from their names.
- (IBAction)BtnSwitchAction:(id)sender {
if (!_formTwo) {
_formTwo = [[DecriptDelegate alloc] initWithWindowNibName:#"frmTwo"];
[_formTwo setFrmStart:self];
}
if(_formOne.isVisible) {
[_window close];
[_formTwo showWindow:sender];
} else if(_formTwo.isVisible) {
[_formTwo close];
[_window showWindow:sender];
}
}
In your nib, make sure both windows have the 'Release when closed' checkbox unchecked so your window is not released when you call close. In your second FormTwo window controller, you should call the BtnSwitchAction from your BtnBackActionPreformed method.
I know there's a number of ways you can connect the window switching code to the back button, but I recommend having all the window switching logic in one method on the AppDelegate rather than manipulating OTHER windows from your BtnBackActionPreformed. That controller and method shouldn't know about the details of the other windows, it should just tell the AppDelegate to do the switch.
I'm new to storyboarding so the answer to this may be simplistic,
I've created a viewController in which a UITextField is present. My test is to transfer the data (text) from that text field into a viewController that is pushed onto the screen.
The coding that i have is as follows:
ViewController1.h -
#import <UIKit/UIKit.h>
#import "ViewController2.h"
#interface ViewController1 : UIViewController
#property (nonatomic, retain) IBOutlet UITextField *inputText;
#end
ViewController1.m
#import "ViewController1.h"
#implementation ViewController
#synthesize inputText;
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"showTextController"]) {
ViewController2 *vc2 = [segue destinationViewController];
vc2.selectedText.text = self.inputText.text;
}
}
#end
ViewController2.h -
#import <UIKit/UIKit.h>
#interface ViewController2 : UIViewController
#property (nonatomic, retain) IBOutlet UILabel *selectedText;
#end
ViewController2.m
#import "ViewController2.h"
#implementation ViewController2
#synthesize selectedText;
#end
The segue between viewController1 and 2 in storyboard is referred to as 'showTextController'.
Is this the correct coding for something so simple? Do i need to be using 'ViewDidLoad' method along with the prepareForSegue:sender method?
It looks correct to me. In fact, this is simpler than we have had in the past since the storyboard takes care instantiating our view controller objects. One thing to note is that if you're using ARC then you shouldn't be retaining your UILabel.
Hope this helps.
Well, I'm learning how to program on a mac, and I'm tired of searching the for answers, can you guys explain me what I did wrong on my program.
First, I dragged 2 buttons on my window (Load Image, and Unload). Then, I dragged a custom view item and here`s what I did with the Test_Loading_ImagesAppDelegate.h:
#import <Cocoa/Cocoa.h>
#interface Test_Loading_ImagesAppDelegate : NSView {
NSWindow *window;
IBOutlet NSView *mypicture;
}
- (IBAction)LoadImage: (id)sender;
- (IBAction)Unload: (id)sender;
#property (assign) IBOutlet NSWindow *window;
#end
After that, I linked up things on Interface Builder normally and made the Test_Loading_ImagesAppDelegate.m:
#import "Test_Loading_ImagesAppDelegate.h"
#implementation Test_Loading_ImagesAppDelegate
#synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
-(IBAction)LoadImage: (id) sender {
NSURL *myurl;
NSImage *image;
NSData *myurldata;
myurl = [NSURL URLWithString:#"http://....jpg"];
myurldata = [NSData dataWithContentsOfURL:myurl];
image = [NSImage initWithData:myurldata];
[mypicture setImage: image];
}
-(IBAction)Unload: (id) sender {
//Well, still thinking how I'm going to do this, and I would like to make another question: If I dealloc the View or something else the image will disappear?
}
#end
Thanks in advance.
Well, after coming here again I've found this http://www.markj.net/iphone-asynchronous-table-image/ it's for iPhone but can be adapted to OS X easily. Thanks.
HI,
I am trying to open an image by clicking a button,
in my .h i have
#interface FirstDetailViewController : UIViewController {
IBOutlet UIButton *premi;
IBOutlet UIImageView *figura;
UIButton *apri;
}
#property (nonatomic, retain) IBOutlet UIButton *apri;
#end
in my .m file
#implementation FirstDetailViewController
- (IBAction)apri:(id)sender {
}
which code I have to use ?
thank you very much
You would also need to include - (IBAction)apri:(id)sender; in your .h.
Your logic is right as far as the button usage, you would connect premi to apri: in Interface Builder.
AS far as "opening" an image, there are many ways to handle an image. You can load a UIImageView with a specified image, or use a UIWebView, or many other ways.
I created a label using Interface Builder, and now I want to set the background color of the label using code instead of IB's color picker. (I want to do this so that I can define the color using RGB and eventually change the colorspace for the label.)
I'm in cocoa. How do I edit the attributes of an IB object using code?
My code looks like this:
//.h file
#import <UIKit/UIKit.h>
#interface IBAppDelegate : NSObject {
UILabel *label;
}
#property (nonatomic, retain) IBOutlet UILabel *label;
#end
//.m file
#import "IBAppDelegate.h"
#implementation IBAppDelegate
#synthesize label;
(memory stuff...)
#end
- (void)applicationDidBecomeActive:(UIApplication*)application
{
self.label.backgroundColor = [UIColor colorWithRed:0.1f
green:0.2f
blue:0.3f
alpha:1.0f];
}
label.backgroundColor = [UIColor greenColor]
There's nothing special about the objects in your XIB file. They're just normal objects.