Property not found although it's in the header - ios

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

Related

How to interrupt a Viewcontroller when another class is finished processing required data

I have two classes, one view controller an another NSObject class that performs async processes, once its done I want to interrupt the view controller similar to what a button does as IBAction, to update UI. I wanted to keep this functionality in modularized for better use in later stages. Is there a way to do this on Objective-c?
CircleDetectionViewController.h:
#import <UIKit/UIKit.h>
#import "CameraController.h"
#interface CircleDetectionViewController : UIViewController <MyDelegate>
#property (weak, nonatomic) IBOutlet UIImageView *screenPreview;
#end
CircleViewController.mm:
#interface CircleDetectionViewController () <CvVideoCameraDelegate>
#end
#implementation CircleDetectionViewController
CvVideoCamera *camera;
//code
#end
CameraController.h:
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "CircleDetectionViewController.h"
#protocol MyDelegate <NSObject>
-(void) updateUI;
#end
#interface CameraController : NSObject <MyDelegate>
#property (nonatomic, strong) AVCaptureDevice *inputDevice;
#property (nonatomic, strong) AVCaptureSession *session;
#property (nonatomic, strong) AVCaptureStillImageOutput *photoOutput;
#property (nonatomic, weak) id <MyDelegate> delegate;
#end
CameraController.m:
#import "CameraController.h"
#import "FlashHelper.h"
#import "ImageProcessor.h"
#implementation CameraController
#synthesize delegate;
FlashHelper *Flash;
ImageProcessor *IMGProcessor;
int shootCounter;
int NUMSHOTS = 2;
-(id)init{
//code
}
For some reason the code says "No type or protocol named MyDelegate"
Any help would be really appreciated!
In NSObject class create a delegate:
#protocol MyDelegate <NSObject>
-(void) updateUI;
#end
and declare a property of delegate
#property (nonatomic, weak) id <MyDelegate> delegate;
In viewcontroller class invoke the delegate class
NSObject class obj.delegate = self;
and implement the delegate method.
Always update your UI from Main Thread.
To get the main thread use this:
dispatch_async(dispatch_get_main_queue(), ^{
// call your delegate method or update UI here
});
For details for delegate methods check this.

Trying to call custom delegate method of subclass of UITextField in iOS

I have a custom delegate that I have created for a subclass of UITextField. In the delegate class, I've declared an enum like this:
MyCustomDelegate.h
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "MyCustomTextField.h"
#interface MyCustomDelegate : NSObject <MyDelegate, UITextFieldDelegate>
#property (nonatomic, strong)MyCustomTextField *customTextField;
#end
MyCustomTextField.h:
#import <UIKit/UIKit.h>
typedef enum {
EnumTypeA,
EnumTypeB,
EnumTypeC,
EnumTypeD,
EnumTypeE
} MyEnumType;
#class MyCustomDelegate;
#protocol MyDelegate <NSObject>
#required
- (void)methodA;
- (void)methodB;
#end
#interface MyCustomTextField : UITextField
#property (nonatomic, weak)id <MyDelegate>myDelegate;
#property (nonatomic) MyEnumType enumType;
#end
Now, I am trying to use this enum in conjunction with my custom UITextField elsewhere in my project, like this:
MyViewController.h
#import "MyCustomTextField.h"
#import "MyCustomDelegate.h"
#import <UIKit/UIKit.h>
#interface MyViewController : UIViewController
#property (weak, nonatomic) IBOutlet MyCustomTextField *mySampleTextField;
#end
MyViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
[self.mySampleTextField setMyEnumType:EnumTypeA];
}
However, I am getting the error, "No visible #interface for 'MyCustomTextField' declares the selector 'setMyEnumType'".
Can anyone see what it is I'm doing wrong?
Objective-C will automatically generate setter for you based on the name of the property (enumType) instead of the name of type (MyEnumType). So your setters should be the following instead:
[self.mySampleTextField setEnumType:EnumTypeA];

Duplicate interface definition for class "ViewController"

At the last line, I got the error: Duplicate interface definition for class "ViewController". I want to do an IBAction. What is the fault? What can I do? Please help me.
//
// ViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#interface SimpleEmailViewController : UIViewController <MFMailComposeViewControllerDelegate>
- (IBAction)showEmail:(id)sender;
#end
#interface ViewController : UIViewController <MFMessageComposeViewControllerDelegate> {
}
-(IBAction)sendMessage:(id)sender;
- (IBAction)showEmail:(id)sender;
#property (nonatomic, strong) IBOutlet UIWebView *site ;
- (IBAction)call:(id)sender;
#property (retain, nonatomic) IBOutlet UIButton *myBotton;
#end
#interface ViewController : UIViewController**i**
The problem is exactly what the error states. You defined #interface viewController twice. Change the name of one to something else. As a side note, it is a terrible idea to name something with a name apple has already used. You should change both viewControllers to something else, more descriptive of what it does, like mailViewController or setupViewController. Weird stuff can happen when you use apple defined names.
#interface FSMainiPadViewController : UIViewController
Why don't you just make it simple like this?
// ViewController.h
#import <UIKit/UIKit.h>
#import <MessageUI/MessageUI.h>
#interface ViewController : UIViewController <MFMailComposeViewControllerDelegate, MFMessageComposeViewControllerDelegate>
// Actions
- (IBAction)showEmail:(id)sender;
- (IBAction)sendMessage:(id)sender;
- (IBAction)call:(id)sender;
// Properties
#property (nonatomic, strong) IBOutlet UIWebView *site;
#property (retain, nonatomic) IBOutlet UIButton *myBotton;
#end

Defining a delegate in a UIView/UIViewController relationship

I have a subclassed UIView called TargetView that is contained in a UIViewController called MainViewController. I want to set MainViewController as the delegate for TargetView so that MainViewController can receive messages from the child view (TargetView).
In my MainViewController (UIViewController) header I have the following:
#import <UIKit/UIKit.h>
#import "TargetView.h"
#class TargetView;
#interface MainViewController : UIViewController <TargetViewDelegate>
#property (strong, nonatomic) IBOutlet TargetView *target;
#property (strong, nonatomic) IBOutlet UILabel *lblResults;
#end
When I set the TargetViewDelegate in the interface declaration, it shows up in code completion so it knows that it's there, but then the build fails with the message: can't find protocol declaration..."
In my TargetView (UIView) class I have the following:
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "MainViewController.h"
#protocol TargetViewDelegate
#required
-(void)receivedTargetTap;
#end
#interface TargetView : UIView{
id<TargetViewDelegate> delegate;
}
#property (nonatomic,strong) NSString *lblResults;
#property (nonatomic,weak) id<TargetViewDelegate> delegate;
#end
Creating custom delegates is uncharted territory for me. Can anyone tell me what I'm doing wrong? Thanks!
I believe your TargetView.h should be :
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#protocol TargetViewDelegate <NSObject>
#required
-(void)receivedTargetTap;
#end
#interface TargetView : UIView
#property (nonatomic, strong) NSString *lblResults;
#property (nonatomic, weak) id<TargetViewDelegate> delegate;
#end
MainViewController.h :
#import <UIKit/UIKit.h>
#import "TargetView.h"
#interface MainViewController : UIViewController <TargetViewDelegate>
#property (strong, nonatomic) IBOutlet TargetView *target;
#property (strong, nonatomic) IBOutlet UILabel *lblResults;
#end
From your code, you must add <NSObject> after your protocol definition, and remove the MainViewController.h import in your TargetView class.
I think there might be a problem with your import statements in both .h files.
Why do you reference MainViewController.h from TargetView.h? It seems like you don't need it. On the other hand, you should remove the forward declaration of #class TargetView in MainViewController.h, and the simple #import "TargetView.h" should be enough.
After that, you'll also need to implement the required - (void)receivedTargetTap;, otherwise the compiler will complain again that the TargetViewDelegate is not fully implemented.

iOS - Custom view with touch event

I'm trying to creating a custom UIView, lets call it FooView.
FooView.h
#import <UIKit/UIKit.h>
#interface FooView : UIView
#property (nonatomic, strong) UITextField *barTextField;
#property (nonatomic, strong) UIButton *submitButton;
#end
FooView.m
#import "FooView.h"
#implementation FooView
#synthesize barTextField = _barTextField;
#synthesize submitButton = _submitButton;
...
#end
FooViewController.h
#import <UIKit/UIKit.h>
#import "FooView.h"
#interface FooViewController : UIViewController
#property (nonatomic, strong) FooView *fooView;
#end
FooViewController.m
#import "SearchViewController.h"
#interface SearchViewController ()
#end
#implementation SearchViewController
#synthesize fooView = _fooView;
#end
I want the button touch event to be implemented in FooViewController, is delegate can achieve this? If YES, how?
Currently, I'm adding the touch event in such a way
FooViewController.m
- (void)viewDidLoad
{
[self.fooView.submitButton addTarget:self action:#selector(submitTapped:) forControlEvents:UIControlEventTouchUpInside];
}
...
- (IBAction)submitTapped
{
...
}
But I don't think this is a good solution, so need some expert advice.
Any idea?
Yes you can implement using delegate
FooView.h
#import <UIKit/UIKit.h>
#protocol FooViewDelegate
-(void)submitButtonClicked:(id)sender;
#end
#interface FooView : UIView
#property (nonatomic, strong) UITextField *barTextField;
#property (nonatomic, strong) UIButton *submitButton;
#property (nonatomic, assign) id<FooViewDelegate> delegate;
#end
FooView.m
#import "FooView.h"
#implementation FooView
#synthesize barTextField = _barTextField;
#synthesize submitButton = _submitButton;
#synthesize delegate;
...
-(IBAction)buttonClicked:(id)sender // connect this method with your button
{
[self.delegate submitButtonClicked:sender];
}
#end
FooViewController.h
#import <UIKit/UIKit.h>
#import "FooView.h"
#interface FooViewController : UIViewController <FooViewDelegate>
#property (nonatomic, strong) FooView *fooView;
#end
FooViewController.m
#import "FooViewController.h"
#interface FooViewController ()
#end
#implementation FooViewController
#synthesize fooView = _fooView;
- (void)viewDidLoad
{
_fooView = [[UIView alloc] init];
_fooView.delegate = self;
}
-(void)submitButtonClicked:(id)sender //delegate method implementation
{
NSLog(#"%#",[sender tag]);
}
#end

Resources