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.
Related
my file AppDelegate.h
#import <Cocoa/Cocoa.h>
#interface AppDelegate : NSViewController <NSApplicationDelegate,NSTableViewDataSource,NSURLConnectionDataDelegate>{
NSMutableArray *users;
NSMutableArray *messages;
NSMutableData *responseData;
NSString *getUsersRequest;
NSString *getMessagesRequest;
int requestStatus;
NSInteger userId;
}
#property (weak) IBOutlet NSTableColumn *tableColumn;
#property (weak) IBOutlet NSTableView *tableUsers;
#property (weak) IBOutlet NSButton *send;
...
I'm trying to create action in xcode:
enter image description here
but I do not see fields "event" and "arguments", Why???
To actually create an action, you should use the .m (implementation) file, not your .h (header) file.
Also, unlike iOS, when developing for OS X and AppKit the options Event and Arguments are not available, this is normal.
I've search the web a day for it but I can't find it:
How Can I change a UIImageView with a button in a another view on Xcode.
I'm new to Xcode.
Add this to your header file in the ImageView ViewController, and connect it:
#property (nonatomic, retain) IBOutlet UIImageView *imageView;
Add to the other ViewController's .m file (don't forget to import your first file):
- (IBAction)btnPressed {
TheOtherViewController *vc = [[TheOtherViewController alloc] init];
vc.imageView.image = [UIImage imageNamed:#"MyImage"];
}
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
First off let me say that I am VERY new to COCOA but I am learning. I have a simple web browser built. It loads a default page, takes URLs from a text field, even has google search. The problem I'm running in to is updating the textfeild with the current URL. I have the code as follows...
In the .h is...
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#interface MustangAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
NSTextField *googleSearch;
WebView *webView;
NSTextField *addressBar;
}
#property (assign) IBOutlet NSWindow *window;
#property (nonatomic, retain) IBOutlet NSTextField *googleSearch;
#property (nonatomic, retain) IBOutlet WebView *webView;
#property (nonatomic, retain) IBOutlet NSTextField *addressBar;
- (IBAction)googleSearch:(id)sender;
- (IBAction)homeAction:(id)sender;
- (IBAction)addressBar:(id)sender;
#end
In the .m I have a bunch so I'll put in what I think is relevant here...
#import "MustangAppDelegate.h"
#implementation MustangAppDelegate
#synthesize window;
#synthesize googleSearch;
#synthesize webView;
#synthesize addressBar;
- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame {
NSURLRequest *currentRequest = [webView request];
NSURL *currentURL = [currentRequest URL];
addressBar.stringValue = currentURL.absoluteString;
}
The code for the above method never get's called. Like I said, I'm very new to OBC & Cocoa but have been programming in things like Perl for many years. Seems like I'm missing some connectivity because I get a warning with the above code that states WebView may not respond to the request. I dug around to find that code but it still seems like I'm missing something...
Thanks
Mike
Just CTRL + drag the -frameLoadDelegate from the IB to the App Delegate of your application, Mustang
use -didFinishLoadForFrame for the URL
and if you need the title use, -didRecieveTitle.
Hope it helped !
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.