IOS UIConstant declaration and calling - ios

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"

Related

Expandable and collapse tableview in swift

I don't know how to implement expandable and collapse tableview in SWIFT. I searched, but nothing in swift. Kindly guide me. How to do that?
My required output
This looks like a framework like CollapseClick.
It's a framework written in Objective-C.
But you can easily implement it in your Swift-Project. Just copy the .h and .m into your project and link it in your Bridging-Header.h file:
#import "CollapseClick.h"
#import "CollapseClickCell.h"
#import "CollapseClickArrow.h"

Why swift cannot find my Objective-C class in ProductModule-Swift.h

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.

How to import another view controller header file when I use Objective-C category?

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.

Can't rename source code - get error 'Thread1: signal SIGABRT'

I dragged an action to the ViewController.h area (which is my dayNight button), as shown:
//
// ViewController.h
//
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
- (IBAction)dayNight:(id)sender;
- (IBAction)insulationClick:(id)sender;
Now I decide I want it to read:
- (IBAction)dayNightClick:(id)sender;
So I rename it manually as shown in above line. I also rename it in the ViewController.m file from:
- (IBAction)dayNight:(id)sender{}
to:
- (IBAction)dayNightClick:(id)sender{}
When I execute the code I get an error as soon as I use my button.
If I manually rename it (without the word Click) it works again.
Why can't I manually modify the code line. Is there another location where I must rename the code too?
The error is:
Thread1: signal SIGABRT
and points to this line of code in the main.m file:
int main(int argc, char *argv[])
{
#autoreleasepool
{
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
I'm sure this is a really basic question.
This happens because your storyboard / nib still points to the old name. The nib files are essentially just XML files in the background so what you need to do is to open your nib/storyboard go to the inspector that shows all the references. You will find that your old reference to the IBAction still exist there. Delete that by hitting the little cross and drag it into the ViewController again and connect it with the function you renamed it to.
Always remember to update both storyboard + .m if you change your method signature in your header file :)
What I discovered is the following:
Go to the story board (ie the view where you can see your GUI representation of your idevice)
Click on the button you wish to rename (we are going to delete it)
Click the button called "Show the connections inspector" (located near top right hand corner of xcode, and looks like a right pointing arrow in a black circle).
There is a section called "Sent Events", and your button event will have a bubble drawn around it with a link to a second bubble with the name of your IBAction.
Click on the tiny cross (x) in the second bubble to delete the event link.
Now you can start again and rename the button to whatever you like. In my example I renamed it from:
(IBAction)dayNight:(id)sender{}
to:
(IBAction)dayNightClick:(id)sender{}
So this is renaming by deleting all references to the button and simply creating it again. Note the other two places to delete it from are:
In the *.h file, example I deleted this line:
(IBAction)dayNight:(id)sender{}
and in the *.m file, example I deleted this code:
(IBAction)dayNight:(id)sender{}
{
// code in here
}
Yes. The button has an associated target/selector which it calls when it's pressed. Look for a line that contains something like this:
[button addTarget:self action:#selector(dayNight:) forControlEvents:UIControlEventTouchUpInside];
and change the selector here too.

static library, get access to self.view

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>

Resources