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

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.

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.

Property not found although it's in the header

I have one view and one View Controller. I am trying to have a reference to View Controller from the view.
PlusCalendarView.h
#interface PlusCalendarView : TSQCalendarView
#property (nonatomic, strong) UIViewController *initialVC;
#end
ViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
[self setUpCalendarView:self.myCalendarView];
self.myCalendarView.initialVC = self; // ERROR: Property initialVC not found on object of type "PlusCalendarView"
}
How come it cannot find initialVC property?
Update:
ViewController.h
#import <UIKit/UIKit.h>
#import <TimesSquare/TimesSquare.h>
#interface PlusCalendarView : TSQCalendarView;
#end
#interface ViewController : UIViewController
#property (nonatomic, strong) NSCalendar *calendar;
#property (strong, nonatomic) IBOutlet PlusCalendarView *myCalendarView;
#end
The problem is that you're declaring PlusCalendarView in ViewController.h AND PlusCalendarView.h. You should remove the #interface declaration from ViewController.h.
Instead, add #class PlusCalendarView in ViewController.h then #import "PlusCalendarView.h" in ViewController.m

Pass value from controller to controller

I'm building my first iOS app to try and learn iOS coding. However, I need to pass a value xAuthToken from one controller to the other. I can't seem to get it working to. I init the value in the first controller ViewController, but then I need it in SettingsController. I keep getting errors and the one it throws now is: Property 'ViewController' not found on object of type 'ViewController'
What am I doing wrong?
ViewController.h
#import <UIKit/UIKit.h>
#import "SettingsController.h"
#interface ViewController : UIViewController <UITextFieldDelegate>
#property (weak, nonatomic) IBOutlet UITextField *txtUsername;
#property (weak, nonatomic) IBOutlet UITextField *txtPassword;
- (IBAction)sigininClicked:(id)sender;
- (IBAction)backgroundTap:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#property (nonatomic) NSString *xAuthToken;
#end
#implementation ViewController
- (IBAction)sigininClicked:(id)sender {
NSString *xAuthToken = #"0";
self.viewController = [[SettingsController alloc] init];
self.viewController.xAuthToken = xAuthToken;
[self performSegueWithIdentifier:#"login_success" sender:self];
}
SettingsController.h
#import <Foundation/Foundation.h>
#interface SettingsController : UIViewController
#end
SettingsController.m
#interface SettingsController ()
#property (weak, nonatomic) IBOutlet UITextField *myTextField;
#property (weak, nonatomic) IBOutlet UISwitch *mySwitch;
#end
#implementation SettingsController
//THIS IS WHERE I NEED XAUTHTOKEN
If you have a segue that presents your SettingsController, pass the information it needs in prepareForSegue. Don't create a new local SettingsController.
You can do something like
viewController = [self.storyboard instantiateviewcontrollerwithidentifier:#"your vc name"];
viewController.Xauthtoken = data;
// Do something else with this.
Or another way ( I don't know if it's good or bad, use it while your vc is already active ):
Use NSNotificationCenter and pass values between it.
Third way is create delegate for first Viewcontroller.
Try this in your ViewController.m:
#import "ViewController.h"
#interface ViewController ()
#property (nonatomic) NSString *xAuthToken;
#end
#implementation ViewController
- (IBAction)sigininClicked:(id)sender {
xAuthToken = #"Your Value Here";
[self performSegueWithIdentifier:#"login_success" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"login_success"]) {
SettingsController *destViewController = segue.destinationViewController;
destViewController.xAuthToken = xAuthToken;
}
}
And in your SettingsController.h
#import <Foundation/Foundation.h>
#interface SettingsController : UIViewController
#property (nonatomic,strong) NSString *xAuthToken;
#end
SettingsController.m
#interface SettingsController ()
#property (weak, nonatomic) IBOutlet UITextField *myTextField;
#property (weak, nonatomic) IBOutlet UISwitch *mySwitch;
#end
#implementation SettingsController
-(void)viewDidLoad{
NSLog("%#",xAuthToken);
}

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.

modal segue won't engage due to instance selector [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have twoo buttons underneath the view controller. One of those buttons makes calculations. The second one shows information about these calculations. For the information I' m using a modal segue to another viewcontroller called werkwijzeViewController. The calculations button doesn't pose problems. On pressing the information button I get "UIStoryboardModalSegue popoverController]: unrecognized selector sent to instance". What's wrong? I'm uploading some of the relevant code:
viewcontroller.h
#import <UIKit/UIKit.h>
#import "breuk.h"
#import "verklaringViewController.h"
#interface ViewController : UIViewController <UIPopoverControllerDelegate>
#property (strong, nonatomic) IBOutlet UITextField *tellerVeld1;
#property (strong, nonatomic) IBOutlet UITextField *noemerVeld1;
#property (strong, nonatomic) IBOutlet UILabel *quotientVeld;
#property (strong, nonatomic) IBOutlet UITextField *tellerVeld2;
#property (strong, nonatomic) IBOutlet UITextField *noemerVeld2;
#property (strong, nonatomic) IBOutlet UIButton *berekenKnop;
#property (strong, nonatomic) breuk *breuk1;
#property (strong, nonatomic) breuk *breuk2;
#property (strong, nonatomic) breuk *hoofdbreuk;
#property (strong, nonatomic) IBOutlet UITextField *uitkomstNoemerVeld;
#property (strong, nonatomic) IBOutlet UITextField *uitkomstTellerVeld;
#property (strong, nonatomic) IBOutlet UILabel *uitkomstStreep;
#property (strong, nonatomic) UIPopoverController *popoverController;
- (IBAction)berekenQuotient:(id)sender;
#end
viewcontroller.m
#import "ViewController.h"
#interface ViewController ()
{
BOOL veldVerplaatst;
}
#end
#implementation ViewController
#synthesize tellerVeld1;
#synthesize noemerVeld1;
#synthesize quotientVeld;
#synthesize tellerVeld2;
#synthesize noemerVeld2;
#synthesize berekenKnop;
#synthesize uitkomstNoemerVeld;
#synthesize uitkomstTellerVeld;
#synthesize uitkomstStreep;
#synthesize breuk1;
#synthesize breuk2;
#synthesize hoofdbreuk;
#synthesize popoverController;
...
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
UIStoryboardPopoverSegue *popoverSegue;
popoverSegue=(UIStoryboardPopoverSegue *)segue;
UIPopoverController *popoverController;
popoverController = popoverSegue.popoverController;
popoverController.delegate = self;
verklaringViewController *verklaringVC;
verklaringVC=(verklaringViewController *)popoverController.contentViewController;
...
}
#end
werkwijzeViewController.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
#interface werkwijzeViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIButton *af;
#property (strong, nonatomic) IBOutlet UITextView *vereenvoudigBreuken;
#property (strong, nonatomic) IBOutlet UITextView *vermenigvuldigBreuken;
#property (strong, nonatomic) NSMutableArray *tabelTellerOntbonden;
#property (strong, nonatomic) NSMutableArray *tabelNoemerOntbonden;
#property (strong, nonatomic) NSMutableArray *tabelGgdOntbonden;
#end
werkwijzeViewController.m
#import "werkwijzeViewController.h"
#interface werkwijzeViewController ()
#end
#implementation werkwijzeViewController
#synthesize tabelGgdOntbonden;
#synthesize tabelNoemerOntbonden;
#synthesize tabelTellerOntbonden;
...
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
tabelTellerOntbonden =[NSMutableArray new];
tabelTellerOntbonden = [((ViewController *)self.presentingViewController).breuk1 ontbindInFactoren:((ViewController *)self.presentingViewController).breuk1.tellerBreuk inTabel:tabelTellerOntbonden];
NSLog(#"%#",tabelTellerOntbonden);
}
#end
breuk.m
#import "breuk.h"
#implementation breuk
#synthesize tellerBreuk;
#synthesize noemerBreuk;
#synthesize origineleNoemerBreuk;
#synthesize origineleTellerBreuk;
#synthesize ggd;
#synthesize quotientBreuk;
...
- (NSMutableArray *)ontbindInFactoren:(int)product inTabel:(NSMutableArray *)tabel
{
for (int priemfactor=1; priemfactor<=product; priemfactor++)
{
while (product%priemfactor==0)
{
[tabel addObject:[NSString stringWithFormat:#"%i",priemfactor]];
}
}
return tabel;
}
#end
You should post the code for all of your IBAction methods tied to your two buttons.
As a glance, it looks to me like the problem is that your prepareForSegue method blindly casts your segue to type UIStoryboardPopoverSegue, and then tries to access the segue's popoverController property.
Your prepareForSegue method will be called for every segue. You need code in your prepareForSegue that checks the segue identifier to make sure you are dealing wit the correct segue before casting it to a UIStoryboardPopoverSegue.

Resources