not sure whats causing these errors - ios

#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
I'm not sure what I changed or how to fix these errors:
Cannot find interface declaration for 'ViewController';
View controller cannot use 'super because it is not a root class

Likely you forgot to sub-class UIViewController (check your header):
#interface ViewController : UIViewController

Related

iOS SDK - Track viewDidLoad method

I am working on a SDK, where I will have to make a call to our server whenever viewDidLoad method of any UIViewController is called in the app integrated with our SDK. I am trying to use Categories as shown below:
#import "DymmyViewController.h"
#interface DymmyViewController ()
#end
#protocol DummyDelgate;
#interface UIViewController (DummyAddition)
-(void)viewDidLoad;
#end
#implementation DymmyViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
#end
#implementation UIViewController (DummyAddition)
-(void)viewDidLoad{
//server call
}
#end
Nothing happens with this and I get a warning saying "Category is implementing a method which will also be implemented by its primary class"
I understand this is not the way to get this done. Is there any other way I can do this? May be using NSNotification?
This is the way to use protocols and delegates. Delegated are good techniques to respond from one class to another class.
DummyView.h
#import <UIKit/UIKit.h>
#class DummyView;
#protocol DummyViewDelegate <NSObject>
- (void)addItemViewController;
#end
#interface DummyView : UIViewController
#property (nonatomic, weak) id <DummyViewDelegate> delegate;
#end
DummyView.m
#import "DummyView.h"
#interface DummyView ()
#end
#implementation DummyView
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)backButtonClicked:(id)sender {
[self.delegate addItemViewController];
}
ViewController.h
#import <UIKit/UIKit.h>
#import "DummyView.h"
#interface ViewController : UIViewController <DummyViewDelegate>
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
{
DummyView *acController;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
acController.delegate = self;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)addItemViewController{
}
Why not just make a tracking view controller available in the SDK. The app dev should then make all of their view controllers of this base type. You might need a couple of base classes (e.g. if you're also using TableViewControllers).
In SDK:
#interface TrackingViewController : UIViewController
#end
#implementation TrackingViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Make the call here
// ....
}
In app:
#import "SDK.h"
#interface MyViewController : TrackingViewController ...

Viewcontroller Dealloc Method Never Gets Called

I know there are many questions like this. I read all. My problem is very simple.
I created a single view app from xcode file>new project>single view app.
Then i added a second uiviewcontroller in storyboard and a new viewcontroller class named secondViewController. I dragged a button to main viewcontroller and by ctrl+drag to secondViewController on storyboard. I did the reverse in secondViewController. And just added dealloc functins with nslog to class files. I also added weak references to uibuttons
Dealloc method of each viewcontroller never gets called when view changes.
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"viewDidLoad 1");
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
NSLog(#"dealloc 1");
}
SeconViewController.m
#import "SecondViewController.h"
#interface SecondViewController ()
#end
#implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
NSLog(#"dealloc 2");
}
#end
ARC is enabled.
Zombies seem to be disabled on product>edit scheme. I am using xcode 6.2. In instruments allocation screen memory rises at each toggle.
What is the problem, I couldnt find?
dealloc calls when object's (Here its viewcontroller object) swipe out from memory.But here in your case you must presenting view controllers from one another that leads to call only viewwilldisappear and diddisappear.
In storyboard if you want to remove those view controllers completely from memory u should call unwind segue

calling a method from same class in xcode

i want to call a method "shows()" but why i am getting the error that "expected identifier or ( " and "use of undeclared identifier self"
ViewController.m
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
{
NSDictionary *inventory;
}
- (void)shows;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
inventory = #{#"Rahul":[NSNumber numberWithInt:11],
#"iOS":[NSNumber numberWithInt:22]};
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)shows
{
NSLog(#"%#",inventory);
}
[self shows];
#end
You can't call [view shows]; in the class scope, you need to call it within a method, like in viewDidLoad
Call it like this:
- (void)viewDidLoad {
[super viewDidLoad];
inventory = #{#"Rahul":[NSNumber numberWithInt:11],
#"iOS":[NSNumber numberWithInt:22]};
// Do any additional setup after loading the view, typically from a nib.
[self shows];//SHOWS call moved here...
}
You can't call this method outside. You can call it inside of anyother method. Like you can call this method in ViewDidLoad.
- (void)viewDidLoad {
[super viewDidLoad];
[self shows];
}
You have to place the code in another method, it can't be left in the open by it self.
Put it in your viewDidLoad: method or elsewhere

IOS UIButton's size gets bigger when touch inside

simple codes..
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
- (IBAction)dragout:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)dragout:(id)sender {
NSLog(#"-----");
}
#end
and in Storyboard, there is 1 button which size is fit in text "button". Link 'sent event:touch drag outside" to "dragout" IBAction.
When I touch button inside and drag my finger to outside of button, i need move more than button size to call "dragout" IBAction. Nearly 3x width&height size. Why is this happens? Thx for read.

this class is not key value coding-compliant for the key image view

Debugger is showing this information:
2013-07-16 15:23:15.731 app2[2501:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x71a4140> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imageview.'
My app currently consist of two view controllers.
'ViewController' has just a button to start the app and pressing the button launches the new view.
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
- (IBAction)startBtn:(id)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)startBtn:(id)sender {
UIViewController *flipViewController = [[UIViewController alloc] initWithNibName:#"AppViewController" bundle:[NSBundle mainBundle]];
[self presentViewController:flipViewController animated:YES completion:NULL];
}
#end
My second view controller 'AppViewController' has a UIImageView and a UIButton. It's code is:
AppViewController.h
#import <UIKit/UIKit.h>
#interface AppViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIImageView *imageview;
#end
and
AppViewController.m
#import "AppViewController.h"
#interface AppViewController ()
#end
#implementation AppViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#end
The problem I am facing is that the moment I connect the property between the 'xib' file and 'h' file by Ctrl-dragging the image view into the 'h' file, my app crashes in the simulator and gives me the error.
I reckon this might be too simple of an error for many of you, however, I am unable to rectify it. I have read numerous posts on this forum and have tried most, including the #synthesize fix and the like.
Your flipViewController should be a AppViewController.
The issue is that AppViewController is a subclass of UIViewController so you are allowed to instantiate it as a UIViewController, but you lose access to all the additional properties that your AppViewController adds on top of UIViewController's.
Your button handler should look like:
- (IBAction)startBtn:(id)sender {
AppViewController *flipViewController = [[AppViewController alloc] initWithNibName:#"AppViewController" bundle:[NSBundle mainBundle]];
[self presentViewController:flipViewController animated:YES completion:NULL];
}

Resources