i'm working on a static library, where i need to have access to self.view
i'm trying to give the caller a reference to self.view by letting him pass it as a parameter
in the header file the .h
- (void) myM:(UIView *)myView;
but this is giving me an error:
expected a type
please can anyone help,
Thank you
Looks like you just need to import the UIKit headers. Add this at the top of your header file:
#import <UIKit/UIKit.h>
Just add a forward declaration to your header:
#class UIView;
if you need to use the view, add this to your .m file:
#import <UIKit/UIKit.h>
Related
I'm trying to install a pre-made custom progress bar in my app and according to the tutorial from the website i got the code from, i need to:
"On the view controller's header file create an IBOutlet property of the type MCPercentageDoughnutView and link it to the object you created on the Interface Builder."
Can someone explain me how do I create an IBOutlet property of the type MCPercentageDoughnutView? I tried doing:
__weak IBOutlet MCPercentageDoughnutView *pieChart;
It gives me the error: Unknown type name 'MCPercentageDoughnutView'. What am i doing wrong?
In header file you should also:
#import "MCPercentageDoughnutView.h"
If the IBOutlet is to be declared in header file, you can do a forward declaration of MCPercentageDoughnutView in the header file and import the class MCPercentageDoughnutView.h file in your implementation file.
#class MCPercentageDoughnutView // In your header file
#import "MCPercentageDoughnutView.h" // In your implementation file
However, if the IBOutlet is to be declared in the implementation file (in your class' extension), the forward declaration in header file is not required.
I have created a Constant.h file
that contains following code
#ifndef myapp_Constants_h
#define myapp_Constants_h
#define cancel_bt #"cancel.png"
#endif
How can I call cancel_btn image as button image
All the #define does for you is to create a macro that gets replaced at compile time.
If you #import your Constant.h file at the top of a second file, any time the string occurs in that second file, the preprocessor will replace it with the string #"cancel.png".
So if you add code that loads a image into a button, you could use cancel_bt as an image name instead of #"cancel.png"
From your question it sounds like you don't know how to replace a button's image through code. You want to use the UIButton method setImage:forState:. See the docs for more info on using it.
just Import your Constants.h file,where you need.
#import "Constants.h"
That's a weird one:
I'm using a DMSplitView instance
Dragging it to my AppDelegate.h which creates an outlet like #property (weak) IBOutlet DMSplitView *verticalSplit;
However, whenever I'm trying to access it, in my AppDelegate.m, I'm getting an error:
No visible #interface for 'AppDelegate' declares the selector verticalSplit
How is that possible? I've done that like 10,000 times before. What sort of bug is that? Any ideas?
P.S. Just tried it as an experiment, and it's official: I cannot add any outlet whatsoever. :S
How are you defining DMSplitView? Did you use the #class directive in the header file? Did you import it in the .m file? Just wondering.
I have this code a Custom class which extends UIImageView in Objective-C.
When I add to the project and add import to bridging header file my swift class can see
and use the code as usual but when i try to compile it.
I always get this error
I don't know why it is only happen to my CarBigImageView, I try to change the name of the file , create new file with new name and copy all the code there but none seem to work.
but other custom view such as Marker seem to be fine?
UPDATE : ADD MORE INFORMATION
here is my bridging header
#import <AFNetworking/AFNetworking.h>
#import <AFNetworking/UIImageView+AFNetworking.h>
#import <GSKeychain.h>
#import <JSONKit.h>
#import "CarBigImageView.h"
#import "sqlite3.h"
#import <time.h>
#import "Bridge.h"
#import "Marker.h"
here is my "CarBigImageView.h"
#import <UIKit/UIKit.h>
#protocol CarBigImageViewDelegate <NSObject>
- (void)didTouchColor:(UIColor*)coloc atPosition:(CGPoint)point;
#end
#interface CarBigImageView : UIImageView
#property (weak, nonatomic) id<CarBigImageViewDelegate> delegate;
#end
and here what it looks in the editor
and the result when compile
How can i solve this?
Make sure you left Xcode know where to find that file: in build settings look for "Objective-C Bridging Header". The value for that field should be something similar to "$(SRCROOT)/path/to/your/Bridging-Header.h" If you fill this out and hit enter, it SRCROOT will expand, and you can check if that full path is correct path.
When I want to transition from one view controller to another, I import the second view controller's header file into my first view controller's header file, by writing #import "SecondViewController.h". However, since I already defined UIColor category in my first view controller, when I try to import the second view controller, I enter the following error: Duplicate interface definition class for SecondViewController.
Here's my FirstViewController.h:
#import
#import "SecondViewController.h"
#interface FirstViewController : UIViewController
#end
#interface UIColor (ColorWithInt)
+ (UIColor *)colorWithR:(CGFloat)red G:(CGFloat)green B:(CGFloat)blue A:(CGFloat)alpha;
#end
I didn't meet any such errors so far when I develop this app, so it's definitely this category that is causing the issue here. So is it feasible to use category when I want to import another view controller class? Or are there any alternative ways to extend UIColor? I just want to define a function that takes RGB as 0 ~ 255 integer, not 0 ~ 1 floating values that UIColor uses on default.
I use iOS 7 and Xcode 5.
You might #import "SecondViewController.h" twice, just check FirstViewController.h/m file if both did that.
I have a feeling you're using this
#interface
instead of
#implementation
in your .m file.
Self Answer
I found out that the issue is not related to either FirstViewController or SecondViewController - let alone the category; it's because I imported almost all class' header file in AppDelegate.h in order to initialize the relationship among UITabBarController, UINavitationController, RootViewController, and Core Data and its lots of required properties. I didn't know that when I import a class in AppDelegate.h I cannot import the class at some other class's header file. Delete #import "FirstViewController.h"; and #import "SecondViewController.h;" in AppDelegate.h and I find my app being build properly now. Thanks to those who left comments in this post.