Get image through instance method - iphone

I am trying to get image in return from the instance method, i am declaring the method in following way, but giving error. I am using NSObject class.
-(UIImage *)getAdImg;
This is giving error that "Expected a type". What does it mean. I normal view controller it is working fine, but in NSObject class it is giving this error. Please guide for the above.
Thanks in advance.
This is my .h file
#import <Foundation/Foundation.h>
#import "JSON.h"
#interface adClass : NSObject
{
NSString *mStrPid;
NSString *mStrAppUrl;
}
#property (nonatomic, strong) NSString *mStrPid;
#property (nonatomic, strong) NSString *mStrAppUrl;
#property (nonatomic, strong) NSMutableArray *mArrAdsDesc;
#property (nonatomic, strong) NSMutableArray *mArrDeviceType;
#property (nonatomic, strong) NSString *mDevice;
#property (nonatomic, strong) NSString *mImgStr;
-(void)iphoneDevice;
-(UIImage *)getAdImg; //(error line)
#end

You have to #import <UIKit/UIKit.h> (where UIImage is declared)

Use this code
-(UIImage *)getAdImg
{
UIImage *image=[[UIImage alloc]init];
image.images=/**An Array of images**/
return ima;
}
Hope it helps!!!

Related

Issues with #import and #class cause _OBJC_CLASS_ referenced from error

I have two classes.
APPagine.h
#import <Foundation/Foundation.h>
#interface APPagineMedia : NSObject
#property (nonatomic, retain) NSString *Immagine;
#property (nonatomic, retain) NSString *Video;
#end
#interface APPagineDescription : NSObject
#property (nonatomic, retain) NSString *Descrizione;
#end
#interface APPagineSommarioLinee : NSObject
#property (nonatomic, retain) NSString *Description;
#property (nonatomic, assign) int IdLinea;
#end
#interface APPagineSommarioCategorie : NSObject
#property (nonatomic, retain) NSString *Nome;
#property (nonatomic, assign) int DestId;
#property (nonatomic, retain) APPagineSommarioLinee *Linee;
#end
#interface APPagineSommario : NSObject
#property (nonatomic, retain) APPagineSommarioCategorie *Categorie;
#end
#interface APPagine : NSObject
#property (nonatomic, assign) NSString *Layout;
#property (nonatomic, assign) int Indice;
#property (nonatomic, retain) NSString *Titolo;
#property (nonatomic, retain) APPagineMedia *Media;
#property (nonatomic, retain) APPagineDescription *Descrizione;
#property (nonatomic, retain) APPagineSommario *Sommario;
#end
APXmlData.h
#interface APXmlData : NSObject
#property (nonatomic, retain) NSString *Lingua;
#property (nonatomic, assign) float Versione;
#property (nonatomic, assign) long long Timestamp;
#property (nonatomic, retain) APPagine *Pagine;
#property (nonatomic, retain) APCategorie *Categorie;
#property (nonatomic, retain) APCarousel *Carousel;
#end
and finally in my controller interface:
#import "APXmlData.h"
#interface APViewController : UIViewController
{
APXmlData *_XmlData;
}
#end
and in implementation:
_XmlData.Timestamp = 123;
_XmlData.Version = 1.0;
_XmlData.Pagine = [[APPagine alloc] init];
_XmlData.Pagine.Layout = #"a";
_XmlData.Pagine.Indice = 1;
_XmlData.Pagine.Titolo = #"titolo";
//[...]
But,
in when i go to set data to
_XmlData.Pagine = [[APPagine alloc] init];
he returns me a linker error, the classic
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_APPagineDescription", referenced from:
objc-class-ref in APPagine.o
"_OBJC_CLASS_$_APPagineMedia", referenced from:
objc-class-ref in APViewController.o
objc-class-ref in APPagine.o
"_OBJC_CLASS_$_APPagineSommario", referenced from:
objc-class-ref in APPagine.o
ld: symbol(s) not found for architecture i386 clang: error: linker command failed with exit code 1
(use -v to see invocation)
My question is: what is correct way to import the classes in my controller?
Should be use #import or #class?
In that order?
What are the classes that require #class or #import?
NOTE
In Build -> Compile Sources, both files are properly configured.
If i remove _XmlData.Pagine = [[APPagine alloc] init]; the apps run well
thanks.
The error you receive is a linker error, not a compiler error, so it looks like your #import was done correctly. Linker errors occur when the program linker cannot find the implementation. I would suggest that you check:
That you have the corresponding #implementation in e.g. APPagine.m
That APPagine.m is included in the project and active for your target in XCode
The problem is your viewController has just
#import "APXmlData.h"
as you are using _XmlData.Pagine = [[APPagine alloc] init]; in your viewController
you should also import APPagine class in your viewController, using
#import "APPagine.h"
The fact that you have a linker error means that the problem is not with your #import or #class declarations. The problem is that your project is missing either the .m files for this class (in case the library includes source that you're supposed to compile yourself) or the library (.a or .dylib or .framework, if the library was already compiled for you). Check the "Build Phases" in your target settings to make sure the necessary files have been included in the project.

Use SKProduct in normal class

I have StoreKit set up in my project and I can get product information from the app store fine, that's all working.
What I'm now trying to do is add an SKProduct as an instance variable in a class of mine, as below:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#interface VideoCell : UITableViewCell
{
IBOutlet UILabel *title;
IBOutlet UILabel *description;
SKProduct *product;
}
#property (retain) IBOutlet UILabel *title;
#property (retain) IBOutlet UILabel *description;
#property (retain) SKProduct *product;
It works fine with just the IBOutlet variables but the SKProduct lines have errors, as follows:
Unknown type name 'SKProduct'
I'm confused because the class name auto-completes but doesn't actually compile...
Any ideas?
It looks like you're missing the import:
#import <StoreKit/StoreKit.h>

Cross class declaration error?

I am trying to do mapping with Restkit and created 2 classes as below. I got the following errors:
Unknown type name "Card" in Campaign.h
Unknown type name "Campaign" in Card.h
Property with 'retain (or strong)' attribute must be of object type
... more but similar errors
My question is there a way to achieve below class declaration by re-using class.
Campaign.h
#import "Card.h"
#interface Campaign : NSObject
#property (nonatomic, strong) NSNumber* campaignId;
#property (nonatomic, strong) NSString* title;
#property (nonatomic, strong) Card* card;
#end
Card.h
#import "Campaign.h"
#interface Card : NSObject
#property (nonatomic, strong) NSNumber* cardId;
#property (nonatomic, strong) NSString* name;
#property (nonatomic, strong) Campaign* campaign;
#end
Usually, in headers, you use forward class declarations, in order to avoid imports conflicts. So in Campaign.h, before your interface, you'd have #class Card, and in Card.h, you'd have #class Campaign. This merely tells the compiler that these class exists & are defined somewhere else; that's usually all you need to know in a header.
Just in case someone need it in future. Here my solution:
Campaign.h
#class Card;
#interface Campaign : NSManagedObject
#property (nonatomic, strong) NSNumber* campaignId;
#property (nonatomic, strong) NSString* title;
#property (nonatomic, strong) Card* card;
#end
Campaign.m
#import "Card.h"
#implementation Campaign
...
#end
Card.h
#class Campaign;
#interface Card : NSManagedObject
#property (nonatomic, strong) NSNumber* cardId;
#property (nonatomic, strong) NSString* name;
#property (nonatomic, strong) Campaign* campaign;
#end
Card.m
#import "Campaign.h"
#implementation Card
...
#end

Calling a function in viewcontroller from appdelegate

I want to call a function in a viewController from my appDelegate but with the following code, it doesn't get called. What am I doing wrong?
AppDelegate.h:
#import <UIKit/UIKit.h>
#import "DetailsToTransfer.h"
#class AccountDetailTransferViewController;
#interface AccountDetailTransferAppDelegate : NSObject <UIApplicationDelegate> {
DetailsToTransfer *objDetailsToTransfer;
}
#property (nonatomic, retain) DetailsToTransfer *objDetailsToTransfer;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet AccountDetailTransferViewController *viewController;
-(void)sendToTransferScreen:(NSArray *)detailsArray;
#end
AppDelegate.m:
....
-(void)sendToTransferScreen:(NSArray *)detailsArray {
[objDetailsToTransfer setLabels:detailsArray];
objDetailsToTransfer = [[DetailsToTransfer alloc]initWithNibName:#"DetailsToTransfer" bundle:nil];
[self.window addSubview:objDetailsToTransfer.view];
}
DetailsToTransfer.h:
#import <UIKit/UIKit.h>
#interface DetailsToTransfer : UIViewController {
NSArray *accountDetailsArray;
UILabel *nameLabel;
UILabel *accountLabel;
IBOutlet UIButton *btnTransfer;
IBOutlet UIButton *btnBack;
}
#property (nonatomic, retain) NSArray *accountDetailsArray;
#property (nonatomic, retain) IBOutlet UILabel *nameLabel;
#property (nonatomic, retain) IBOutlet UILabel *accountLabel;
-(IBAction)sendDetails;
-(IBAction)goBack;
-(void)setLabels:(NSArray *)array;
#end
DetailsToTransfer.m
....
-(void)setLabels:(NSArray *)array {
NSLog(#"Setting Labels");
self.nameLabel.text = [array objectAtIndex:0];
self.accountLabel.text = [array objectAtIndex:1];
}
....
I would like to add that all the properties have been synthesized and that I'm calling the method in the appDelegate properly (i checked using NSLogs)
In AppDelegate.m:
Looks as if you are calling a method on your object before the object has been created. Until you have alloc / init your object, there will be no labels to set text.
Try changing your method to this:
-(void)sendToTransferScreen:(NSArray *)detailsArray {
if (!objDetailsToTransfer) {
objDetailsToTransfer = [[DetailsToTransfer alloc]initWithNibName:#"DetailsToTransfer" bundle:nil];
[objDetailsToTransfer setLabels:detailsArray];
[self.window addSubview:objDetailsToTransfer.view];
}
}
The problem might be that you are trying to set the values on a object that hasn't been created yet. I also provided an if statement to prevent the object from being created multiple times.

Load a view .xib in MainWindow.xib

It`s probably a very silly mistake, but I've spent over 4 days looking for a solution for this.
It is very simple, I´ve got my MainView.xib and a view called FirstViewController (h/m/xib).
In MainWindow.xib I add a UIViewController and change the class name to FirstViewController and set the Nib name also (altouhg I've tried both ways).
I guess it has to do something with outlets, but I can`t really tell, as I am a newbie developing for iOS, any help wil REALLY help a lot.
Im using XCode 3.2 and interface builder, with SDK 4.3
AppDelegate
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface iPadTerritorioV2AppDelegate : NSObject <UIApplicationDelegate> {
IBOutlet UIWindow *window;
IBOutlet UIViewController *navigationController;
NSString *devToken;
NSString *matricula;
NSString *campus;
NSMutableArray *materiasAlumno; //para CCM
NSMutableArray *busqDir; //para CCM
NSInteger agendaBadgeNumber;
NSInteger intramurosBadgeNumber;
NSInteger notificacionesBadgeNumber;
NSInteger mapaBadgeNumber;
NSMutableData *receivedData;
NSMutableDictionary *listData;
BOOL yaSeHizoElPrimerFetchBadges;
}
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) IBOutlet UIViewController *navigationController;
#property (nonatomic, retain) NSString *devToken;
#property (nonatomic, retain) NSString *matricula;
#property (nonatomic, retain) NSString *campus;
#property (nonatomic, retain) NSMutableArray *materiasAlumno;
#property (nonatomic, retain) NSMutableArray *busqDir;
#property NSInteger agendaBadgeNumber;
#property NSInteger intramurosBadgeNumber;
#property NSInteger notificacionesBadgeNumber;
#property NSInteger mapaBadgeNumber;
#property (nonatomic, retain) NSMutableData *receivedData;
#property (nonatomic, retain) NSMutableDictionary *listData;
#property BOOL yaSeHizoElPrimerFetchBadges;
- (void)fetchBadges;
#end
FirstViewController.h
#import <UIKit/UIKit.h>
#import "Constants.h"
#import "StringDecoding.h"
#define kConnectionBadgeNotifications 0
#define kConnectionLogin 1
#define kConnectionDevToken 2
#define kCCMindex 0
#define kCSFindex 1
#define kMTYindex 2
#interface FirstViewController : UIViewController {
IBOutlet UISegmentedControl *segmentedCampus;
IBOutlet UITextField *usernameField;
IBOutlet UITextField *passwordField;
IBOutlet UISwitch *remembermeSwitch;
IBOutlet UIButton *loginButton;
UIActivityIndicatorView *loginIndicator;
NSMutableDictionary *listData;
NSMutableData *receivedData;
NSInteger connectionID;
}
#property (nonatomic, retain) UISegmentedControl *segmentedCampus;
#property (nonatomic, retain) UITextField *usernameField;
#property (nonatomic, retain) UITextField *passwordField;
#property (nonatomic, retain) UIActivityIndicatorView *loginIndicator;
#property (nonatomic, retain) UISwitch *remembermeSwitch;
#property (nonatomic, retain) UIButton *loginButton;
#property (nonatomic, retain) NSMutableDictionary *listData;
#property (nonatomic, retain) NSMutableData *receivedData;
#property NSInteger connectionID;
- (IBAction)handleNextClick:(id) sender;
- (IBAction)backgroundClick;
- (IBAction)login: (id) sender;
#end
It sounds like your FirstViewController isn't being retained - if it's not assigned to an outlet anywhere, nothing's retaining it and it'll just disappear. Add a property somewhere (your AppDelegate, perhaps, if that's all you've got) and connect it to the controller:
#property (nonatomic, retain) IBOutlet UIViewController *firstViewController;