Why get " expected selector for Objective-C method" Error - objective-c

I have this code:
#class GADBannerView,GADRequest;
#interface BT_viewController : UIViewController <UIAlertViewDelegate,
ADBannerViewDelegate,
UIAccelerometerDelegate,
MFMailComposeViewControllerDelegate,
MFMessageComposeViewControllerDelegate,
GADBannerViewDelegate>{
BT_item *screenData;
UIView *progressView;
GADBannerView *bannerView_;
/* iAd Views */
UIView *adView;
ADBannerView *adBannerView;
BOOL adBannerViewIsVisible;
BOOL hasStatusBar;
BOOL hasNavBar;
BOOL hasToolBar;
}
#property (nonatomic, retain) BT_item *screenData;
#property (nonatomic, retain) UIView *progressView;
#property (nonatomic, retain) UIView *adView;
#property (nonatomic, retain) ADBannerView *adBannerView;
#property (nonatomic) BOOL adBannerViewIsVisible;
#property (nonatomic) BOOL hasStatusBar;
#property (nonatomic) BOOL hasNavBar;
#property (nonatomic) BOOL hasToolBar;
-(id)initWithScreenData:(BT_item *)theScreenData;
-(void)showProgress;
-(void)hideProgress;
-(void)navLeftTap;
-(void)navRightTap;
-(void)showAudioControls;
-(void)showAlert:(NSString *)theTitle theMessage:(NSString *)theMessage alertTag:(int)alertTag;
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
//iAd methods...
-(void)createAdBannerView;
-(void)resizeAdView;
-(void)showHideAdView;
-(void)bannerViewDidLoadAd:(ADBannerView *)banner;
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error;
//shake capture...
-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event;
//message compose delegate methods...
-(void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result;
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;
//rotation methods...
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation;
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation;
#property(nonatomic, strong) GADBannerView *bannerView;
- {GADRequest *}createRequest;
#end
I don't know why at this line:
- {GADRequest *}createRequest;
it gives an error:"expected selector for Objective-C method"
But if I remove some code above that lines it is ok.
Could you figure out what is the error here ? Sorry since I am newbie I quite confuse about the meaning of the error message.
Thank you.

I believe you are trying to declare an instance method. Change it as follows.
- (GADRequest *)createRequest; //To This
- {GADRequest *}createRequest; //From this

Related

property not found on object of type error but property is there

So I'm trying to access the property isPortClosed(BOOL) in SerialPortController and its giving me an error, I'm kinda new to objective-c. I feel like this should work as I've got a reference to the class with *port. Here is a link to the project.
Error messages: ~/GroundStation/GroundStation/ViewController.m:16:22: Property 'isPortClosed' not found on object of type 'SerialPortController *'
#import <Cocoa/Cocoa.h>
#import "SceneView.h"
#import "SerialPortController.h"
#interface ViewController : NSViewController
#property (strong) IBOutlet SerialPortController *port;
#property (weak) IBOutlet SceneView *accelSceneView;
#end
#import "ViewController.h"
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
while(!self.port.isPortClosed) {
}
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
#end
SerialPortController.h class
#import <Foundation/Foundation.h>
#import <ORSSerial/ORSSerial.h>
#interface SerialPortController : NSObject <ORSSerialPortDelegate>
#property (nonatomic, strong) ORSSerialPort *serial;
#property (nonatomic, strong) ORSSerialPortManager *serialPortManager;
#property (nonatomic) NSInteger xAngle;
#property (nonatomic) NSInteger yAngle;
#property (nonatomic) NSInteger zAngle;
#property (nonatomic) NSString *stringBuffer;
#property (nonatomic) BOOL isPortClosed;
#end
From the downloaded project I see that you have two SerialPortController class definitions (one at the root directory, and one in /GroundStation/), and the latter doesn't have any public properties. You should have only one SerialPortController class definition linked in your project (the one with the public properties).

How to silent warning incompatible property type

I am using RTSPagedView from github in my project. Which gives me this warning
Property type 'id<RTSPagedViewDelegate>' is incompatible with type 'id<UIScrollViewDelegate>' unherited from 'UIScrollView'
in
#property (nonatomic, assign) IBOutlet id <RTSPagedViewDelegate> delegate;
in RTSPagedView.h
App is working fine with this warning. Anyone came across this before or knows the solution please help.
Link for this is RTSPagedView
// RTSPagedView.h
// PagedView
// http://github.com/rplasman/RTSPagedView
#import <UIKit/UIKit.h>
#protocol RTSPagedViewDelegate;
#interface RTSPagedView : UIScrollView
#property (nonatomic, assign) IBOutlet id <RTSPagedViewDelegate> delegate;
#property (nonatomic, assign) NSUInteger currentPage;
#property (nonatomic, readonly) NSUInteger numberOfPages;
#property (nonatomic, assign) BOOL continuous;
- (void)resizeBounds:(CGRect)bounds;
- (UIView *)dequeueReusableViewWithTag:(NSInteger)tag;
- (UIView *)viewForPageAtIndex:(NSUInteger)index;
- (void)scrollToPageAtIndex:(NSUInteger)index animated:(BOOL)animated;
- (void)reloadData;
- (NSUInteger)indexForView:(UIView *)view;
#end
#protocol RTSPagedViewDelegate <UIScrollViewDelegate>
- (NSUInteger)numberOfPagesInPagedView:(RTSPagedView *)pagedView;
- (UIView *)pagedView:(RTSPagedView *)pagedView viewForPageAtIndex:(NSUInteger)index;
#optional
- (void)pagedView:(RTSPagedView *)pagedView didScrollToPageAtIndex:(NSUInteger)index;
- (void)pagedView:(RTSPagedView *)pagedView didRecycleView:(UIView *)view;
#end
Try it this way:
#property (nonatomic, assign) IBOutlet id <UIScrollViewDelegate, RTSPagedViewDelegate> delegate;
Works for me.
Issue occurred because
#property (nonatomic, assign) IBOutlet id <RTSPagedViewDelegate> delegate;
In this delagate is poniting towards UIScrollViewDelagate because RTSPagedView is inherited from UIScrollView.
Modify the complete delegate name with any other name like
#property (nonatomic, assign) IBOutlet id <RTSPagedViewDelegate> rtspDelegate;
It will remove the warning.
I think (I cannot be sure without more code) that you are haven't declared your delegate class as conforming to the RTSPagedViewDelegate protocol.
try this:
YourClass.h:
#interface YourClass : NSObject <UIScrollViewDelegate, RTSPagedViewDelegate>
...
#end
And now when you do:
rtsPageView.delegate = self;
The warning should be gone.
This could be complete rubbish, in which case I'll delete it.

Categories instance methods do not invoke

I have a class(Core Data Generated):
#interface Place : NSManagedObject
#property (nonatomic, retain) NSString * title;
#property (nonatomic, retain) NSString * subtitle;
#property (nonatomic, retain) NSNumber * latitude;
#property (nonatomic, retain) NSNumber * longitude;
#end
#implementation Place
#dynamic title;
#dynamic subtitle;
#dynamic latitude;
#dynamic longitude;
#end
Adn a category for it:
#interface Place (Create)
+ (Place *)placeWithTitle:(NSString *)title
inManagedObjectContext:(NSManagedObjectContext *)context;
+(Place *) placeWithTitle:(NSString *)title andSubtitle:(NSString *)subtitle inManagedObjectContext:(NSManagedObjectContext *)context;
+(Place *) placeWithCoordinate:(CLLocationCoordinate2D) coordinate inManagedObjectContext:(NSManagedObjectContext *)context;
- (void) setLattitudeAndLongitudeByCoordinate:(CLLocationCoordinate2D) coordinate;
- (CLLocationCoordinate2D) coordinate;
#end
In this category a have to instance methods:
- (void) setLattitudeAndLongitudeByCoordinate:(CLLocationCoordinate2D) coordinate
{
self.latitude=[NSNumber numberWithDouble:coordinate.latitude];//break point HERE
self.longitude=[NSNumber numberWithDouble:coordinate.longitude];
}
-(CLLocationCoordinate2D) coordinate
{
CLLocationCoordinate2D coord;//break point HERE
coord.latitude=[self.latitude doubleValue];
coord.longitude=[self.longitude doubleValue];
return coord;
}
As you see i have to breakpoints there. Now, then i call those methods
#import "Place+Create.h"
-(void)someMethod
{
[self.place setLattitudeAndLongitudeByCoordinate:coordiante];
}
It never seem to reach those breakpoints inside the method setLattitudeAndLogitudeByCoordinate,
and debug shows that it even doesn't call them! Why?
Is someMethod ever reached? Check that using a breakpoint or an extra NSLog at its head.
If not, then your problem is somewhere else as your program flow is different than you expected it to be.
If it is reached then self.place obviously is nil. That means you never initialized it and again, your program flow is different than you thought it would be.

create control with properties within it

I have control something like this
#import <Foundation/Foundation.h>
#import "AQLevelMeter.h"
#import "AQPlayer.h"
#import "AQRecorder.h"
#interface SpeakHereController : NSObject {
IBOutlet UIBarButtonItem* btn_record;
IBOutlet UIBarButtonItem* btn_play;
IBOutlet UILabel* fileDescription;
IBOutlet AQLevelMeter* lvlMeter_in;
AQPlayer* player;
AQRecorder* recorder;
BOOL playbackWasInterrupted;
BOOL playbackWasPaused;
}
#property (nonatomic, retain) UIBarButtonItem *btn_record;
#property (nonatomic, retain) UIBarButtonItem *btn_play;
#property (nonatomic, retain) UILabel *fileDescription;
#property (nonatomic, retain) AQLevelMeter *lvlMeter_in;
#property (readonly) AQPlayer *player;
#property (readonly) AQRecorder *recorder;
#property BOOL playbackWasInterrupted;
#property BOOL isReport;
#property CFStringRef recordFilePath;
- (IBAction)record: (id) sender;
- (IBAction)play: (id) sender;
-(void) InitializeThePlayer;
#end
as we can see I added many properties like
#property BOOL isReport;
#property CFStringRef recordFilePath;
then I created uiview contains this control
#import <UIKit/UIKit.h>
#class SpeakHereController;
#interface SpeakHereViewController : UIViewController {
IBOutlet SpeakHereController *controller;
}
Now I want to access the properties of the control object so I say
- (void)viewWillAppear:(BOOL)animated {
[self ReportDirectory];
[controller setIsReport:self.iSReport ];
//controller.isReport = self.iSReport ;
[controller setRecordFilePath:(CFStringRef) self.DICOMpath];
//controller.recordFilePath = ;
}
the problem is that at the lines
[controller setIsReport:self.iSReport ];
[controller setRecordFilePath:(CFStringRef) self.DICOMpath];
there is warning say that
warning: no '-setIsReport:' method found
I made
#synthesize isReport;
#synthesize recordFilePath;
also if I replaced #class SpeakHereController; by #import "SpeakHereController.h" it raise a lot of errors , U can download the sample code from apple
and if I said controller.isReport = self.iSReport ; it raise error request for member 'isReport' in something not a structure or union
My question is how to call the properties in this control , am I missing something
Best regards
I tried
At the top of SpeakHereViewController.m you will need
import "SpeakHereController.h"
Otherwise when SpeakHereViewController.m is compiled, it is completely unaware of what methods and properties your SpeakHereController class has
It should run fine even with the warning because the property does exist. However, I agree with you that the warning needs to be dealt with.
You should synthesize those properties in .m file.
The syntax is like:
#synthesize isReport, recordFilePath;

inheritance working on simulator but not on Iphone!

I have come across a weird error...
I have a class that extends another, getting some variables from it. Its a really simple one.
when i compile the code for the simulator, it works great. When I run in the Iphone, it get an error that states that the vairable is not set!. The code:
parent class header:
#import <UIKit/UIKit.h>
#import "TarefaMap.h"
#interface GenericTarefaTableView : UITableViewController {
TarefaMap* tarefaMap;
TarefaMap* tarefaMapOriginal;
}
#property (nonatomic, retain) TarefaMap* tarefaMap;
#property (nonatomic, retain) TarefaMap* tarefaMapOriginal;
#end
parent class implementation:
#import "GenericTarefaTableView.h"
#implementation GenericTarefaTableView
#synthesize tarefaMap,tarefaMapOriginal;
#end
child class header:
#interface EditTarefaViewController : GenericTarefaTableView <UITextFieldDelegate , UITextViewDelegate> {
Tarefa* tarefa;
NSArray *fieldLabels;
UITextField *textFieldBeginEdited;
BOOL isEdit;
IBOutlet UITableViewCell *cell0;
IBOutlet UITextView* textView;
NSManagedObjectContext* context;
}
#property (nonatomic, retain) NSManagedObjectContext* context;
#property (nonatomic, retain) IBOutlet UITextView* textView;
#property (nonatomic, retain) IBOutlet UITableViewCell *cell0;
#property (nonatomic, retain) Tarefa* tarefa;
#property (nonatomic, retain) UITextField* firstField;
#property (nonatomic, retain) NSArray *fieldLabels;
#property (nonatomic, retain) UITextField *textFieldBeingEdited;
#end
Child class implementation:
#import "EditTarefaViewController.h"
#implementation EditTarefaViewController
#synthesize tarefa, textFieldBeingEdited,firstField,fieldLabels,textView, cell0, context;
NSMutableArray *textFieldarray;
UIActionSheet *actionSheet;
UITableViewCell* cell1;
- (void)viewDidLoad
{
NSLog(#"ViewDidLoad");
[super viewDidLoad];
self.tarefaMap=[[TarefaMap alloc] initWithTarefa:tarefa];
self.tarefaMapOriginal=[[TarefaMap alloc] initWithTarefa:tarefa];
if ([tarefaMapOriginal isEqual:tarefaMap]) {
NSLog(#"SOMOS IGUAIS!!!!!");
}
NSLog(#"Comparando tarefas!!!!!");
if ([tarefaMapOriginal isEqualtoTarefaMap:tarefaMap]) {
NSLog(#"SOMOS IGUAIS2!!!!!");
}
}
This compiles fine on the simulator, but when i Try on the IPhone, I get an error saying that the variables tarefaMap is undeclared, and should be declared on the function...
any thoughts?
#interface EditTarefaViewController : GenericTarefaTableView <UITextFieldDelegate , UITextViewDelegate> {
before that line add this
#class GenericTarefaTableView;
then in .m file add
import "GenericTarefaTableView.h"
and change like in viewdidload
NSLog(#"ViewDidLoad");
[super viewDidLoad];
super.tarefaMap=[[TarefaMap alloc] initWithTarefa:tarefa];
super.tarefaMapOriginal=[[TarefaMap alloc] initWithTarefa:tarefa];
#implementation EditTarefaViewController
before that u have to import TarefaMap.h and also declare this in EditTarefaViewController.h file with like this
#class TarefaMap;