Cannot find delegate defined in another header - ios

I have a very simple problem, yet because it's so simple, I can't find anything wrong with it to fix.
ListSelectorUtility.h
#import <UIKit/UIKit.h>
#protocol ListSelectorDelegate <NSObject>
- (void) returnValueString:(NSString *)value requestID:(long)requestID;
#end
#interface ListSelectorUtility : UITableViewController
#property (strong, nonatomic) NSString *data;
#property (weak, nonatomic) id<ListSelectorDelegate> delegate;
#property (nonatomic) long requestID;
#end
UpdateProperty.h
#import <UIKit/UIKit.h>
#import "ListSelectorUtility.h"
#interface UpdateProperty : UITableViewController <ListSelectorDelegate>
#property (nonatomic, strong) NSDictionary *data;
#end
There's an error on the #interface UpdateProperty : UITableViewController <ListSelectorDelegate> saying that No type or protocol named 'ListSelectorDelegate'. Why is this happened? How to solve this? Thanks.
EDIT: oh, and when I do CMD+click on the <ListSelectorDelegate>, it brings me straight up to the ListSelectorDelegate declaration. That means the IDE (supposedly) can find it.

set property of delegate (strong) on ListSelectorUtility.h
#property (strong, nonatomic) id<ListSelectorDelegate> delegate;
may bey problem of that because if it is week then dealloc by ARC and call the delegate method on ListSelectorUtility.h on your pass the data and values
[self.delegate returnValueString:obj_StringValue requestID:obj_requestID];
And finally this delegate method declare in UpdateProperty.h,
- (void) returnValueString:(NSString *)value requestID:(long)requestID
{
//---------
//Your Code
//---------
}

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.

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.

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.

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.

Resources