Just trying to make a simple WebView Mac app.
I've imported WebKit.h, declared a WebView #property, and #synthesized it in the .m, but when I go into IB and the connections tab, my outlet, say MyWebView, is not listed.
.h
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#interface MyAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
IBOutlet WebView *MyView;
}
#property (assign) IBOutlet NSWindow *window;
#property (nonatomic, retain) IBOutlet WebView *MyView;
#end
.m
#synthesize MyView;
Latest version of Xcode. Thoughts?
Make sure that is defined like:
#property(nonatomic, retain) IBOutlet UIWebView *myWebView;
If you haven't added IBOutlet, IB won't show it as such.
After looking at the code you posted a little more carefully, I think the problem has to do with the name of your app delegate -- how (and why?) did you change it from the default AppDelegate? Is the blue cube in IB named AppDelegate or is it named MyAppDelegate? If it's the former, that's your problem -- change its class to MyAppDelegate in the Identity Inspector in IB.
See my comments on my original question. Error on my part.
Related
I'm new to objective-c. When I'm reading some source code written by others, I encountered a problem.
I found that there is
IBOutlet NSPopover *popover;
as well as
#property NSPopover *popover;
PopoverViewController.h
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import "TimerPopoverViewController.h"
#class TimerLogic;
#class TimerInfo;
#interface TimerPopoverDelegate : NSObject <NSPopoverDelegate> {
#private
IBOutlet NSPopover *popover;
IBOutlet NSWindow *detachWindow;
IBOutlet TimerPopoverViewController *viewController;
}
#property NSPopover *popover;
- (void)showPopover:(id)sender timerInfo:(TimerInfo *)timerInfo;
#end
I think they are different variables. However, I can't figure out what do they do?
As far as I'm concerned, the IBOutlet is to show a popover.
But what does the #property does?
This is either very old code or written in a very old (and now discouraged) style. The IBOutlet here is declaring an instance variable (ivar). The #property is declaring a property that is backed by the instance variable. In modern ObjC you should implement it this way:
PopoverViewController.h
#import <Cocoa/Cocoa.h>
#class TimerInfo;
// Things declared here are public
#interface TimerPopoverDelegate : NSObject <NSPopoverDelegate>
// You could leave this here if it is required by other parts of the program,
// but other parts of the program really shouldn't require it. See below.
// #property (nonatomic, readonly, weak) NSPopover *popover;
- (void)showPopover:(id)sender timerInfo:(TimerInfo *)timerInfo;
#end
PopoverViewController.m
// Generally avoid importing local headers into the .h unless you have to.
#import "TimerPopoverViewController.h"
// Things declared here are private. This is much better than the old #private.
#interface TimerPopoverDelegate ()
#property (nonatomic, readwrite, weak) IBOutlet NSPopover *popover;
#property (nonatomic, readwrite, weak) IBOutlet NSWindow *detachWindow;
#property (nonatomic, readwrite, weak) IBOutlet TimerPopoverViewController *viewController;
#end
(Currently popover is public, but you should avoid exposing an IBOutlet that way. Outside objects should not directly touch a view controller's outlets.)
I am creating a iPad app, using XCode4 and Storyboard. I have the exact same app on a iPhone, which works just fine. I copied all of the controller's .h and .m files to the new iPad app. There are NO build errors. I am using custom cells in several UITableViews, with prototype cells.
I have 4 IBOutlets defined in a .h file, which is included in the UIView controller's .h file. I'm trying to connect the IBOutlets to the objects in the prototype cells, but when I click on the controller, the objects don't appear in the Inspector.
Any idea why?
UPDATE: here is the code for the SiteListingCell.h.
#import <UIKit/UIKit.h>
#interface SiteListingsCell : UITableViewCell {
}
#property (nonatomic, strong) IBOutlet UILabel *staLabel;
#property (nonatomic, strong) IBOutlet UILabel *descLabel;
#property (nonatomic, strong) IBOutlet UILabel *dateLabel;
#end
Make sure the class of the object you're trying to connect is set correctly in IB:
I have a simple project using Xcode 4.3.2 targeting iOS 5.1, using storyboards and a NavigationController. I have just migrated the project to use ARC and I'm now noticing that memory isn't being reclaimed when my UITableViewController scene is popped (back button pressed). I'm sure this was working OK when I was managing memory myself. I'm using the 'Allocations' feature of the Instruments tool and I can see the 'Live Bytes' continues to increase each time the scene is pushed then popped. The interface for the UITableViewController is :
#import <UIKit/UIKit.h>
#import "ASIHTTPRequest.h"
#interface StockListView : UITableViewController <UISearchBarDelegate>
{
NSMutableArray *tableListArray;
IBOutlet UISearchBar *searchBarControl;
}
#property (nonatomic) ASIHTTPRequest *httpDSRequest;
#end
The UITableView uses a custom UITableViewCell class defined as follows :
#import <UIKit/UIKit.h>
#interface StockListCell : UITableViewCell
#property (nonatomic) IBOutlet UILabel *lblStockCode;
#property (nonatomic) IBOutlet UILabel *lblDescription;
#property (nonatomic) IBOutlet UILabel *lblQtyInStock;
#property (nonatomic) IBOutlet UILabel *lblQtyFree;
#end
Is there something in the properties I'm using that is keeping the view controller retainined in memory? Do I need to add some code to allow the view controller to fully deallocate now that I'm using ARC?
I also used the 'Leaks' feature of Instruments but this didn't show up any leaks present.
Any help appreciated, apologies I'm still new to iOS development.
Thanks
Jonathan
You should make the buttons weak referenced
#property (weak, nonatomic) IBOutlet UILabel *lblStockCode;
And maybe have a look at this: ARC Transition
I was following the steps here: http://matt.might.net/articles/how-to-native-iphone-ipad-apps-in-javascript/
Here are the bare bones steps to turning a web app into a native app:
Open XCode.
Create a new "View-based Application" iPhone project.
Move the files for your web app into the Resources folder in XCode,
but strip out the cache manifest. (You don't want the manifest
screwing things up, since everything is now local.)
Create a new instance variable, webView, inside the #interface
ViewController header file: IBOutlet UIWebView* webView ; //
IBOutlet means it's visible to Interface Builder.
and create a property: #property (nonatomic, retain) UIWebView
*webView;
Here is what I have thus far (ViewController.h):
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
IBOutlet UIWebView* webView;
#property (nonatomic, retain) UIWebView *webView;
#end
However on step 4 I am getting two errors in my ViewController header file:
"cannot declare variable inside #interface or #protocol"
and
"iboutlet attribute can only be applied to instance variables or
properties"
So what am I doing wrong, or is that website tutorial wrong?
Note: I downloaded the sample project he had for iPhone and it worked, but I am following the tutorial so I can make an iPad version.
I am in XCode 4 and the error shows whether I do iOS 5 or iOS 4.3 doesn't seem to make a difference.
You're missing a couple of curly braces there:
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
UIWebView *webView;
}
#property (nonatomic, retain) IBOutlet UIWebView *webView;
#end
I think you forgot the brackets; try to change your code to
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController {
IBOutlet UIWebView* webView;
}
#property (nonatomic, retain) UIWebView *webView;
#end
I am attempting to hide a NSButton that performs miniaturize when a different NSButton on the interface is clicked. My attempts thus far have been unsuccessful, this is what I have tried:
.h file:
#interface AppDelegate : NSObject <NSApplicationDelegate> {
IBOutlet NSWindow *window;
IBOutlet WebView *webView;
IBOutlet NSButton *doMinimize;
}
#property (assign) IBOutlet NSWindow *window;
#property (assign) IBOutlet NSButton *button;
#property (nonatomic, retain) IBOutlet WebView *webView;
.m file:
#implementation AppDelegate
#synthesize window;
#synthesize webView;
#synthesize doMinimize;
- (IBAction)toggleFullscreen:(id)sender
{
...
[doMinimize setEnabled:NO];
[doMinimize setTransparent:YES];
...
}
It appears that no matter in what action I try to disable and make the button transparent, it doesn't seem to respond to anything. Do I have to give the button it's own class to make this work? If so, how would I then be able to modify that button from an IBAction inside of a different class?
I apologize in advance if my question is silly, I'm relatively new to the world of Objective-C and am just now starting to get my feet wet.
Thanks in advance.
Have you tried -setHidden:?
[doMinimize setHidden:YES];