Declared Interface errors when building the project - ios

I im fairly new to ios development, and following the tutorial exercise on chapter 4 of the book 'beginning ios5 development' i have run into some compile errors on my code.
here's what my header code .h file looks like
#import <UIKit/UIKit.h>
#interface BIDViewController : UIViewController
#property (strong, nonatomic) IBOutlet UITextField *namefIELD;
#property (strong, nonatomic) IBOutlet UITextField *numberField;
#property (strong, nonatomic) IBOutlet UILabel *sliderLabel;
#property (strong, nonatomic) IBOutlet UISegmentedControl *leftSwitch;
#property (strong, nonatomic) IBOutlet UISegmentedControl *rightSwitch;
#property (strong, nonatomic) IBOutlet UIButton *doSomethingButton;
-(IBAction)textFieldDoneEditing:(id)sender;
//to initialize the 'done' button when editing to confirm you have finished editing/
-(IBAction) backgroundTap:(id)sender;
- (IBAction)sliderChanged:(id)sender;
- (IBAction)switchChanged:(id)sender;
- (IBAction)toggleControls:(id)sender;
- (IBAction)buttonPressed:(id)sender;
#end
and here's my .m code where im facing the error "no visible #interface for 'UISegmentedControl' declares the selector 'setOn:animated;'
#synthesize leftSwitch;
#synthesize rightSwitch;
- (IBAction)switchChanged:(id)sender {
UISwitch *whichSwitch = (UISwitch *)sender;
BOOL setting = whichSwitch.isOn;
[leftSwitch setOn: setting animated: YES]; //the error lies here/
[rightSwitch setO: setting animated: YES]; //the error lies here/
}
- (IBAction)toggleControls:(id)sender {
}
- (IBAction)buttonPressed:(id)sender {
}
#end
the error statement is "no visible #interface for 'UISegmentedControl' declares the selector 'setOn:animated;'
pls help, that would be highly appreciated and voted for :)
#PhilipMills ...here's what i'm talking about, as soon as i click on a leftside or rightside of the segmented control object a break point is automatically made on my delegated header code here
#import <UIKit/UIKit.h>
#import "BIDAppDelegate.h"
int main(int argc, char *argv[])
{
#autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([BIDAppDelegate class])); //the breakpoint appears here.
}
}

A UISwitch has a setOn:animated: method but a UISegmentedControl does not. I'll guess that you assigned objects to leftSwitch and rightSwitch that are not the kind you intended (or the tutorial intended).

Related

Cannot specify setter 'setTitle:' for properties of NSObject or WKInterfaceController

I am trying to set up a WKInterfaceTable. I followed Apples docs. My Label is not getting text and I get this error message in console:
Cannot specify setter 'setTitle:' for properties of NSObject or WKInterfaceController
How can I fix this? Objective-C please. Here s my code:
.h
#import <Foundation/Foundation.h>
#import <WatchKit/WatchKit.h>
#interface MainRowType : NSObject
#property (strong, nonatomic) IBOutlet WKInterfaceImage *image;
#property (strong, nonatomic) IBOutlet WKInterfaceLabel *title;
#end
.m
#import "MainRowType.h"
#implementation MainRowType
#end
.h
#import <WatchKit/WatchKit.h>
#import <Foundation/Foundation.h>
#import "MainRowType.h"
#interface WatchTableController : WKInterfaceController
#property (strong, nonatomic) IBOutlet WKInterfaceTable *tableView;
#property (strong, nonatomic) NSMutableArray *titleArray;
#end
.m
I call this method
- (void)configureTableWithData:(NSMutableArray*)dataObjects {
[self.tableView setNumberOfRows:[dataObjects count] withRowType:#"mainRowType"];
for (NSInteger i = 0; i < self.tableView.numberOfRows; i++) {
MainRowType* theRow = [self.tableView rowControllerAtIndex:i];
NSString *titleString = [dataObjects objectAtIndex:i];
[theRow.title setText:titleString];
}
}
Thanks
Your title property is the problem. You can't name a property "title" in those classes. Change the property name and you should be all set.

How come "self.canDisplayBannerAds = YES;" makes app crash on iOS 8?

I would like to point out that self is a WelcomeViewController and that it inherits from UIViewController :
WelcomeViewController.h
#import <UIKit/UIKit.h>
#interface WelcomeViewController : UIViewController
#property (strong, nonatomic) NSString* score;
#property (strong, nonatomic) NSUserDefaults* preferences;
#end
WelcomeViewController.m
#import "WelcomeViewController.h"
#import "GESceneController.h"
#import <iAd/iAd.h>
#interface WelcomeViewController ()
#property (weak, nonatomic) IBOutlet UILabel *scoreLabel;
#property (weak, nonatomic) IBOutlet UILabel *highScoreLabel;
#end
#implementation WelcomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.canDisplayBannerAds = YES;
[self.scoreLabel setText:self.score];
NSString* highScoreText = [NSString stringWithFormat:#"Meilleur score : %ld",
[self.preferences integerForKey:#"highscore"]];
[self.highScoreLabel setText:highScoreText];
// Do any additional setup after loading the view.
}
and I get the error : [WelcomeViewController setCanDisplayBannerAds:]: unrecognized selector sent to instance 0x7d97f080
Have you imported the iAd file into your linked frameworks and libraries? If not, goto your build info and scroll all the way to the bottom, there you will find 'linked frameworks..' and add the framework into you app.

Objective-C inheritance [duplicate]

This question already has answers here:
Objective-C: How do you access parent properties from subclasses?
(5 answers)
Closed 9 years ago.
I'm making a very simple app that has lots of different quizzes. My motivation is primarily to learn Objective-C and iOS development. So I have a few views in my app, all of them have the same background which I set programmatically. I decided to make a subclass of UIViewController which added the function setBackground, and make all ViewControllers in my app inherit this subclass (SumsViewController).
This worked fine, but now I'd like to take out some of the stuff that's common to each quiz and add that in to a subclass of SumsViewController, called QuizController. Having tried this I'm getting errors about property x not found on object of type y.
Here's the code:
SumsViewController.h
#import <UIKit/UIKit.h>
#interface SumsViewController : UIViewController
- (void)setBackground;
#end
SumsViewController.m
#import "SumsViewController.h"
#interface SumsViewController ()
#end
#implementation SumsViewController
- (void)setBackground
{
... //Code to set Background
}
#end
QuizController.h
#import <UIKit/UIKit.h>
#import "SumsViewController.h"
#interface QuizController : SumsViewController
#property (nonatomic) NSInteger number1;
#property (nonatomic) NSInteger number2;
#property (nonatomic) NSInteger difficulty;
#property (nonatomic) NSInteger score_val;
#property (nonatomic) NSTimer* countdown;
#property (nonatomic) NSInteger time_val;
#end
QuizController.m
#import "QuizController.h"
#interface QuizController ()
#end
#implementation QuizController
#end
Now here's a controller for a quiz that inherits QuizController:
AdditionController.h
#import <UIKit/UIKit.h>
#import "QuizController.h"
#interface AdditionController : QuizController
#end
AdditionController.m
#import "AdditionController.h"
#import "ViewController.h"
#interface AdditionController ()
#property (weak, nonatomic) IBOutlet UILabel *question;
#property (weak, nonatomic) IBOutlet UILabel *timer;
#property (weak, nonatomic) IBOutlet UIButton *ans1;
#property (weak, nonatomic) IBOutlet UIButton *ans2;
#property (weak, nonatomic) IBOutlet UIButton *ans3;
#property (weak, nonatomic) IBOutlet UILabel *score;
#end
#implementation AdditionController
- (void)viewDidLoad
{
[super viewDidLoad];
[self setBackground]; //function declared in SumsViewController WORKS FINE
self.difficulty = 20; //declared in QuizController DOES NOT WORK
// Error says property not member of object AdditionController
[self setupGame];
}
#end
I'd appreciate any help on this, I'm sure it's a simple misunderstanding but this is frustrating me.
Try cleaning you project and re building files ( Command + Shift + K ).
I'm suggesting that because I just copied your code in a sample project, and it works fine on my computer.

Inheritance on view controller Objective c

I am trying to create a generic view controller and 2 other views which both will inherit from.
Now this is the generic view (what i think is relevant - if something else is needed i will add it):
#interface CardGameViewController ()
#property (strong, nonatomic) IBOutlet UITabBarItem *TabSelection;
#property (strong, nonatomic) CardMatchingGame *game;
#property (strong, nonatomic) IBOutlet UIButton *resetButton;
#property (weak, nonatomic) IBOutlet UILabel *scoreLable;
#property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *cardButtons;
#end
#implementation CardGameViewController
- (CardMatchingGame*)game
{
if(!_game) _game = [[CardMatchingGame alloc]initWithCardCount:[self.cardButtons count] usingDeck:[self createDeck] gameMode:[self getActiveTabWithString:self.TabSelection.description]];
return _game;
}
- (Deck*)createDeck //abstract
{
return nil; <------- Relevant generic function
}
and these are the 2 files which inherit the mentioned file:
SetGameViewController.h:
#import "CardGameViewController.h"
#interface SetGameViewController : CardGameViewController
#end
SetGameViewController.m:
#import "SetGameViewController.h"
#import "SetCardDeck.h"
#interface SetGameViewController ()
#end
#implementation SetGameViewController
-(Deck*)createDeck
{
return [[SetCardDeck alloc]init];
}
#end
and the second one:
PlayingCardGameViewController.h:
#import "CardGameViewController.h"
#interface PlayingCardGameViewController : CardGameViewController
#end
PlayingCardGameViewController.m:
#import "PlayingCardGameViewController.h"
#import "PlayingCardDeck.h"
#interface PlayingCardGameViewController ()
#end
#implementation PlayingCardGameViewController
- (Deck*)createDeck
{
return [[PlayingCardDeck alloc]init];
}
#end
I also have tab bar navigator to switch between the 2 views.
The thing is, the first (SetGameViewController) is never instantiated no matter what i do,
Meaning the createDeck function is never called,
While the second one (PlayingCardGameViewController) is ok every time.
What i have tried:
placing break points on the main view - (CardMatchingGame*)game function.
this one only gets called when i am trying to start the second working view, and not the bad one.
If there is anything missing to give a certain lead, please let me know and i will add it.
Set breakpoints on the empty createDeck method in the base class, as well as on the method in your two subclasses.
My guess is that when you set up your tab bar controller in IB (Interface Builder) , you made one of the tabs be an instance of the generic CardGameViewController instead of a SetGameViewController.

Why is my Segmented control not reacting?

I am working with an iPhone application in Xcode and I want to use a segmented control with 4 different choices.
I am wondering what I am doing wrong and why the NSLog messages don't show when I click on it?
This is my code:
.h file:
#import <Foundation/Foundation.h>
#interface Format : UIViewController{
IBOutlet UISegmentedControl *papper;
}
#property (nonatomic, retain) IBOutlet UISegmentedControl *papper;
-(IBAction)papperskontrollSwitched:(id)sender;
.m file:
#import "Format.h"
#implementation Format
#synthesize papper;
-(IBAction)papperskontrollSwitched:(id)sender{
if(papper.selectedSegmentIndex==0){
NSLog(#"A5 valdes");
}
else if(papper.selectedSegmentIndex==1){
NSLog(#"A4 valdes");
}
else if(papper.selectedSegmentIndex==2){
NSLog(#"A3 valdes");
}
else if(papper.selectedSegmentIndex==3){
NSLog(#"Visitkort valdes");
}
}
#end
Try deleting the stuff in the brackets:
{
IBOutlet UISegmentedControl *papper;
}
There's no need for it when you have this:
#property (nonatomic, retain) IBOutlet UISegmentedControl *papper;
Having an ivar and a #property shouldn't matter here and indeed when I'm using this exact code in a test project it is working perfectly.
Ensure your UISegmentedControl is connected to the papper outlet in Interface Builder and you've connected the UISegmentedControl's 'Value Changed' action to -(IBAction)papperskontrollSwitched:

Resources