Not responding to selector : delegate - ios

I want to send the information from Players View Controller to Current Match View Controller using a delegate. The only thing is that PlayersViewCotroller and GameDetailsViewController are seperated by another view controller. What should I do to make sure that the selector is being called? Am I missing anything?
#import <UIKit/UIKit.h>
#class PlayersViewController;
#protocol PlayersViewControllerDelegate <NSObject>
- (void)addItemViewController:(PlayersViewController *)controller didFinishEnteringPlayer1:(NSString *)player1 didFinishEnteringPlayer2:(NSString *)player2;
#end
#interface PlayersViewController : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *player1;
#property (weak, nonatomic) IBOutlet UITextField *notes1;
#property (weak, nonatomic) IBOutlet UITextField *player2;
#property (weak, nonatomic) IBOutlet UITextField *notes2;
#property (weak, nonatomic) IBOutlet UIBarButtonItem *nextButton;
- (IBAction)nextButtonPressed:(id)sender;
#property (nonatomic, weak) id <PlayersViewControllerDelegate> pdelegate;
#end
PlayersViewController.m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqual:#"playersSegue"]) {
if([self.pdelegate respondsToSelector:#selector(addItemViewController:didFinishEnteringPlayer1:didFinishEnteringPlayer2:)]){
[self.pdelegate addItemViewController:self didFinishEnteringPlayer1: player1.text didFinishEnteringPlayer2: player2.text];
NSLog(#"Works");
}
}
CurrentMatchViewController.m (sending the info to this view controller)
- (void)addItemViewController:(PlayersViewController *)controller didFinishEnteringPlayer1:(NSString *)player1 didFinishEnteringPlayer2:(NSString *)player2 {
NSLog(#"%#", player1);
}

Related

-[MyDictationController respondsToSelector:] message sent ot deallocated instance

My app crashes with this stack trace:
[DictationDetailsController respondsToSelector:]: message sent to deallocated instance
I tracked that on instruments trying to see the relevant code causing the crash:
here is the relevant code for MyDictationController in the didSelectRowAtIndexPath: delegate method:
- (void)tableView:(UITableView )tableView didSelectRowAtIndexPath:(NSIndexPath )indexPath {
DictationDetailsController *controller = GET_CONTROLLER_WITH_CLASS([DictationDetailsController class]);
controller.dictation = [unSubmittedDictations objectAtIndex:indexPath.row];
controller.isEditMode = YES;
controller.selectedDate = _selectedDate;
controller.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:controller animated:YES];
}
#property (copy ,nonatomic) Dictation *dictation;
Also i have used #synthesize. Help me out in this issue, to get which deallocated method is being called.?
Here's my DictationDetailsController interface:
#interface DictationDetailsController : BaseController
#property (copy ,nonatomic) Dictation *dictation;
#property (nonatomic) BOOL isEditMode;
#property (nonatomic) NSDate *selectedDate;
#property (weak, nonatomic) IBOutlet UILabel *navigationTitleLabel;
#property (weak, nonatomic) IBOutlet UITextField *patientNameTextField;
#property (weak, nonatomic) IBOutlet UITextField *accountIDTextField;
#property (weak, nonatomic) IBOutlet UITextField *workTypeTextField;
#property (weak, nonatomic) IBOutlet NSLayoutConstraint *deleteButtonWidth;
#property (weak, nonatomic) IBOutlet UIView *tutorialView;
#property (weak, nonatomic) IBOutlet UIView *audioContainer;
#property (weak, nonatomic) IBOutlet UISlider *audioSlider;
#property (weak, nonatomic) IBOutlet UILabel *durationLabel;
#property (weak, nonatomic) IBOutlet UILabel *noRecordingLabel;
#property (weak, nonatomic) IBOutlet UIButton *playPauseButton;
#end
And in dealloc method:
- (void)dealloc {
[player pause];
player = nil;
self.dictation = nil;
}
My guess is the issue is somewhere inside GET_CONTROLLER_WITH_CLASS method. Pop a breakpoint on that line and step over it. It's possibly producing a released instance of the class. That being the case, the crash would occur on the line immediately following the call to that method when it tries to access the dictation property.

cannot find protocol declaration for delegate

these 2 are the files where i m creating a protocol and then declare the delegate in another class
this is my favouriteViewController.h
#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>
#import "ViewController.h"
#class FavouritesTableViewController;
#protocol FavouritesTableViewControllerDelegate<NSObject>
- (void)senDetailsViewController:(FavouritesTableViewController *)controller didFinishEnteringItem:(NSArray *)item;
#end
#interface FavouritesTableViewController : UITableViewController <UISearchControllerDelegate,UISearchBarDelegate>
#property (strong, nonatomic) IBOutlet UISearchController *search;
#property (strong, nonatomic) IBOutlet UITableView *table;
#property (nonatomic, weak) id < FavouritesTableViewControllerDelegate > delegate;
#end
and this is my viewController.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "FavouritesTableViewController.h"
#interface ViewController : UIViewController <CLLocationManagerDelegate,FavouritesTableViewControllerDelegate>
#property (weak, nonatomic) IBOutlet UIImageView *weatherIcon;
#property (weak, nonatomic) IBOutlet UILabel *Place;
#property (weak, nonatomic) IBOutlet UILabel *Temperature;
#property (weak, nonatomic) IBOutlet UILabel *unit;
#property (weak, nonatomic) IBOutlet UILabel *weatherText;
#property (weak, nonatomic) IBOutlet UITextView *Info;
#property (weak, nonatomic) IBOutlet UILabel *summary;
#property (strong,nonatomic) NSString *longitude;
#property (strong,nonatomic) NSString *latitude;
#property (strong,nonatomic) NSString *locationName;
#property BOOL setLocation;
#property (weak, nonatomic) IBOutlet UIScrollView *scroll;
- (IBAction)forecast:(UIButton *)sender;
- (IBAction)Share:(UIButton *)sender;
- (IBAction)history:(UIButton *)sender;
#property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activIndicator;
- (IBAction)favbutton:(id)sender;
#end
the error i get is
:- Cannot find protocol declaration for
'FavouritesTableViewControllerDelegate'
I'm declaring these methods and protocols to pass data from FavouriteViewController to ViewController
and this is the protocol method which i call in ViewController.m
-(void)senDetailsViewController:(FavouritesTableViewController *)controller didFinishEnteringItem:(NSArray *)item
{
controller.delegate = self;
self.latitude = [item[0] valueForKey:#"lat"];
self.longitude = [item[0] valueForKey:#"long"];
self.locationName = [item[0] valueForKey:#"name"];
self.setLocation = YES;
[self viewDidLoad];
}
Ths is happening because of recursive import, in FavouritesTableViewController you are importing "ViewController.h" and again ViewController.h you are importing "FavouritesTableViewController.h"
try
#class viewController;
#class FavouritesTableViewController;
in FavouritesTableViewController.h and remove "#import ViewController.h"

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);
}

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.

Custom delegate not getting called

I am trying to use Delegates to communicate thru view controllers. Here is my code:
#protocol ViewControllerDelegate;
#interface ViewController : UIViewController <UITextFieldDelegate>{
IBOutlet UIDatePicker *dateTimePicker;
}
#property (nonatomic, strong) IBOutlet UITextField *className;
#property (nonatomic, strong) IBOutlet UITextField *assignmentTitle;
#property (nonatomic, strong) IBOutlet UITextField *assignmentDescription;
#property (nonatomic, strong) IBOutlet UISwitch *procrastinationNotificationSwitch;
#property (nonatomic, strong) IBOutlet UILabel *notificationOnOffLabel;
#property (nonatomic, assign) id <ViewControllerDelegate> delegate;
#property (nonatomic,strong)classObject *classObject;
-(IBAction) addButton:(id)sender;
#end
#protocol ViewControllerDelegate <NSObject>
-(void)assignmentSaved:(classObject *)classObj;
In action:
[self.delegate assignmentSaved:self.classObject];
In other view controller:
-(ViewController *)vc
{
if (!_vc) {
_vc = [[ViewController alloc]init];
}
return _vc;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.vc.delegate = self;
}
-(void)assignmentSaved:(classObject *)classObj
{
NSLog(#"%#",classObj.description);
classObj2 = classObj;
[self.tableView reloadData];
}
vc is a property of View Controller. When I NSLog the delegate, the delegate ends up to be nil. Also I tried #mialkan answer yet it still does not work. If you need any more info just ask.
I made some changes in your code, and dont forget to #synthesize delegate; and dont for get to setDelegate:self where you create ViewController.
#protocol ViewControllerDelegate;
#interface ViewController : UIViewController <UITextFieldDelegate>{
IBOutlet UIDatePicker *dateTimePicker;
id <ViewControllerDelegate> delegate;
}
#property (nonatomic, strong) IBOutlet UITextField *className;
#property (nonatomic, strong) IBOutlet UITextField *assignmentTitle;
#property (nonatomic, strong) IBOutlet UITextField *assignmentDescription;
#property (nonatomic, strong) IBOutlet UISwitch *procrastinationNotificationSwitch;
#property (nonatomic, strong) IBOutlet UILabel *notificationOnOffLabel;
#property (nonatomic, assign) id <ViewControllerDelegate> delegate;
#property (nonatomic,strong)classObject *classObject;
-(IBAction) addButton:(id)sender;
#end
#protocol ViewControllerDelegate
-(void)assignmentSaved:(classObject *)classObj;
#end
In the first view did you subscribe to your delegate < ViewControllerDelegate > ?
MyOtherViewController : UIViewController <ViewControllerDelegate>
and you can only do that :
- (void)viewDidLoad
{
[super viewDidLoad];
if (!_vc)
_vc = [[ViewController alloc]init];
self.vc.delegate = self;
}

Resources