Incomplete Implementation Errror - objective-c

Keep getting a error on the last line #implementation line saying implementation incomplete. Not sure what the problem is. What would cause this? I posted the header too.
Added the rest of the code from the .m file.
#import "mmViewController.h"
#interface mmViewController ()
-(void)timerFired:(NSTimer*)theTimer;
#end
#implementation mmViewController
#synthesize remainingTime, playerScore, scrambledWord;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)viewDidLoad
{
[super viewDidLoad];
//Do any additional setup after loading the view, typically from a nib.
//Initialize the game model
gameModel = [[mmScramblerModel alloc] init];
//Display the time, score and scrambled word
remainingTime.text = [NSString stringWithFormat:#"%i", gameModel.time];
playerScore.text = [NSString stringWithFormat:#"%i", gameModel.score];
scrambledWord.text = [gameModel getScrambledWord];
//Start the game timer
gameTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(timerFired:)
userInfo:nil
repeats:YES];
}
-(void) endGameWithMessage:(NSString *)message {
//Call this method to end the game
//Invalidate the timer
[gameTimer invalidate];
//Show an alert with the results
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:#"Game Over!"
message:message
delegate:self
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
-(void) timerFired:(NSTimer *)theTimer {
//The timer fires this method rougly every second
[gameModel timerTick];
if(gameModel.time <= 0){
remainingTime.text = 0;
[self endGameWithMessage:#"You are out of time. You lose!"];
}
else
remainingTime.text = [NSString stringWithFormat:#"%i", gameModel.time];
}
#end
#import <UIKit/UIKit.h>
#import "mmScramblerModel.h"
#interface mmViewController : UIViewController {
mmScramblerModel* gameModel;
NSTimer* gameTimer;
}
-(IBAction)guessTap:(id)sender;
-(void) endGameWithMessage:(NSString*) message;
#property (weak, nonatomic) IBOutlet UITextField * guessText;
#property (weak, nonatomic) IBOutlet UILabel * scrambledWord;
#property (weak, nonatomic) IBOutlet UILabel * remainingTime;
#property (weak, nonatomic) IBOutlet UILabel * playerScore;
#end

Look at the methods listed in the .h file. Now look at the methods that you actually implemented. SInce there are only two, it's pretty easy to notice that you didn't implement one of them.
Implement the guessTap: method.

From your code i can see the interface declaration of
-(IBAction)guessTap:(id)sender;
But you have not implemented this method in .m file

remove the guessTap: method from interface

Related

Incomplete implementations

I'm working on a project in Xcode and getting an error from didReceiveMemoryWarning and incomplete implementation. This is the main file:
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#interface LoginViewController : UIViewController
#property (strong, nonatomic) IBOutlet UIScrollView *scroller;
#property (weak, nonatomic) IBOutlet UITextField *FirstNameField;
#property (weak, nonatomic) IBOutlet UITextField *SurnameField;
#property (weak, nonatomic) IBOutlet UITextField *EmailField;
#property (weak, nonatomic) IBOutlet UITextField *PasswordField;
#property (weak, nonatomic) IBOutlet UITextField *ReenterPasswordField;
- (IBAction)RegisterAction:(id)sender;
#end
This is .m file:
#import "LoginViewController.h"
#interface LoginViewController ()
#end
#implementation LoginViewController
#synthesize scroller;
- (void)viewDidLoad
{
[super viewDidLoad];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake(340, 600)];
}
- (void)viewDidAppear:(BOOL)animated
{
PFUser *user = [PFUser currentUser];
if (user.email != nil) {
[self performSegueWithIdentifier:#"login" sender:self];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)RegisterAction:(id)sender {
[_FirstNameField resignFirstResponder];
[_SurnameField resignFirstResponder];
[_EmailField resignFirstResponder];
[_PasswordField resignFirstResponder];
[_ReenterPasswordField resignFirstResponder];
[self checkFieldsComplete];
[self checkFieldsComplete];
}
- (void) checkFieldsComplete {
if ([_FirstNameField.text isEqualToString:#""] || [_SurnameField.text isEqualToString:#""]|| [_EmailField.text isEqualToString:#""] || [_PasswordField.text isEqualToString:#""] || [_ReenterPasswordField.text isEqualToString:#""]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops" message: #"Make sure to complete every field" delegate: nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
} else {
[self checkPasswordsMatch];
}
}
- (void) checkPasswordsMatch {
if (![_PasswordField.text isEqualToString:_ReenterPasswordField.text]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Oops" message: #"Passwords don't match" delegate: nil cancelButtonTitle: #"Ok" otherButtonTitles: nil];
[alert show];
}
}
- (void) registerNewUser {
PFUser *newUser;
newUser.username = [NSString stringWithFormat: _FirstNameField.text, _SurnameField.text];
newUser.email = _EmailField.text;
newUser.password = _PasswordField.text;
[newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!error) {
NSLog(#"Welcome to Vici!");
[self performSegueWithIdentifier:#"login"
sender:self];
} else {
NSLog(#"There was an error in registration");
}
}];
}
#end
Can anyone point out a solution?
You are missing a closing brace at viewDidAppear, and thus it's getting confused by the rest of the #implementation and complaining because it's not finding RegisterAction as a result. It's showing you the warning at didReceiveMemoryWarning because that was the first bit of code after your missing brace (which shows you how to find the issue in the future).
Add the missing brace and you should get past this error.

how to delegate with an IBAction between two different UIViewController

I'm just trying to understand how delegate works and I'm in troubles.
I have two classes (both UIViewController) connected into the storyboard, the first one (ViewController.h/m) hold a TableView with cells and the second one (AddNameViewController.h/m) simply hold a TextField (where I want to write) and a button (Add Name)
as you surely understand I want the button pressed to send to the TableView what is written into the TextField, pretty simple.
And since I have two different Controllers and an Array containing the data holds by the tableview, I want to connect them with a delegate (just to learn it).
here is some code:
ViewController.h
#import "AddNameViewController.h"
#interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, AddNameViewControllerDelegate>
#property (strong, nonatomic) NSMutableArray *array;
#end
ViewController.m
#import "ViewController.h"
#import "AddNameViewController.h"
#inferface ViewController ()
#end
#implementation ViewController
#synthesize array;
-(void)addStringWithString:(NSString*)string
{
[self.array addObject:string];
NSLog(#"%#", array);
}
-(void)viewDidLoad
{
AddNameViewController *anvc = [[AddNameViewController alloc] init];
anvc.delegate = self;
array = [[NSMutableArray alloc] initWithObjects:#"first", #"second", nil];
NSLog(#"%#", array);
[super viewDidLoad];
}
-(NSInteger)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSindexPath*)indexPath
{
static NSString *simpleTableIdentifier = #"RecipeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
#end
AddNameViewController.h
#protocol AddNameViewControllerDelegate <NSObject>
-(void)addStringWithString:(NSString*)string;
#end
#interface AddNameViewController : UIViewController
#property (weak, nonatomic) id <AddNameViewControllerDelegate> delegate;
#property (weak, nonatomic) IBOutlet UITextField *myTextField;
-(IBAction)add:(id)sender;
#end
finally the AddNameViewController.m
#import "ViewController.h"
#interface AddNameViewController ()
#end
#implementation AddNameViewController
#synthesize myTextField, delegate;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}
-(void)viewDidLoad
{
[super viewDidLoad];
}
-(IBAction)add:(id)sender
{
[self.delegate addStringWithString:self.myTextField.text];
// I've also tried with this but nothing --> [self.delegate addStringWithString:#"aa"];
}
#end
The array is initialized properly, no errors, no warnings, no crashes, simply seems like the method "addStringWithString" is not even called, because is not even NSLog anything.
obviously everything in connected in the storyboard, methods and outlets, thanks for your help.
in interface builder of AddNameViewController, did you connect the button event (Touch Up inside) into the action -(IBAction)add:(id)sender ?
also try this
-(IBAction)add:(id)sender
{
if([self.delegate respondsToSelector:#selector(addStringWithString:)]) {
[self.delegate addStringWithString:self.myTextField.text];
}
// I've also tried with this but nothing --> [self.delegate addStringWithString:#"aa"];
}

delegate gets null when performWithSegue

Im trying to send some info from a modal view to a delgate. But it seems like my delegate doesnt follow through, it gets null. It looks like this in IB http://i.imgur.com/7oaxb.png.
But it works if i remove the navigationController that is right before the modal view and use the buttons in the View.
please help, ive tried for like 5 hours... :/
Heres the modalViewController code:
#import
#import "Link.h"
#protocol modalViewDelegate <NSObject>
-(void)closeview;
-(void)saveLink:(Link *)link;
#end
#interface modelViewController : UIViewController
#property (weak, nonatomic) IBOutlet UITextField *titel;
#property (weak, nonatomic) IBOutlet UITextField *url;
#property (nonatomic, weak) id <modalViewDelegate> delegate;
- (IBAction)exitModal:(id)sender;
- (IBAction)saveLink:(id)sender;
#end
and .m:
#import "modelViewController.h"
#interface modelViewController ()
#end
#implementation modelViewController
#synthesize titel;
#synthesize url, delegate;
- (IBAction)exitModal:(id)sender {
//[self.delegate closeview];
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)saveLink:(id)sender {
if (titel.text.length > 0 && url.text.length > 0) {
NSString *urlen = [NSString stringWithFormat:#"%#", url.text];
Link *linken = [[Link alloc] initWithURL:[NSURL URLWithString:urlen]];
linken.title = titel.text;
NSLog(#"%#", delegate); **//returns null when pressing button** it returns null if i put it in viewDidLoad to..
[self.delegate saveLink:linken];
[self dismissModalViewControllerAnimated:YES];
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:#"warning" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil, nil];
[alertView show];
}
}
#end
the MasterViewController .h (that pushes the modalview:
#import <UIKit/UIKit.h>
#import "modelViewController.h"
#class DetailViewController;
#interface MasterViewController : UITableViewController <modalViewDelegate>
....
and .m
#import "MasterViewController.h"
#import "DetailViewController.h"
#implementation MasterViewController
#synthesize detailViewController = _detailViewController;
#synthesize links;
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"linkPush"]) {
// Skicka länken till detaljvyn
DetailViewController *detailVC = segue.destinationViewController;
detailVC.link = [self.links objectAtIndex:self.tableView.indexPathForSelectedRow.row];
NSLog(#"%#", detailVC);
}
//this is the modalview "pusher"
if ([segue.identifier isEqualToString:#"newLink"]) {
modelViewController *mvc = segue.destinationViewController;
mvc.delegate = self;
NSLog(#"%#", mvc.delegate);
}
}
- (void)closeview {
[self dismissModalViewControllerAnimated:YES];
//[self.tabBarController dismissModalViewControllerAnimated:YES];
}
-(void)saveLink:(Link *)link{
NSLog(#"hello");
[links insertObject:link atIndex:links.count]; //updates a Tableview and works fine if delegate is called
[self.tableView reloadData];
//[self dismissModalViewControllerAnimated:YES];
}
If your destination view controller is wrapped into a navigation controller, you have to refer to it differently in prepareForSegue:
UINavigationController *nav = segue.destinationViewController;
DetailViewController *dvc = [nav.viewControllers objectAtIndex:0];
Now setting the properties, including the delegate, should work.

UIPopoverController Delegate Problem?

I have a UIPopover that I want to use either
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
return NO;
}
or
-(void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController{}
on. Neither of them seem to work (and I'm sure once one is fixed, the other will be too since it's probably a problem with delegates). For delegates, here is what I have:
In optionsViewController.h, the view which is inside the popover:
#import <UIKit/UIKit.h>
#protocol OptionsViewControllerDelegate <NSObject>
-(void)didPick:(NSString *)string;
#end
id delegate;
#interface OptionsViewController : UIViewController <OptionsViewControllerDelegate>{
IBOutlet UIPickerView *picker;
NSMutableArray *list;
}
#property (nonatomic, copy) NSArray *passthroughViews;
#property(nonatomic,retain) NSMutableArray *list;
#property(nonatomic,assign) id<OptionsViewControllerDelegate> delegate;
#end
and in the .m:
#synthesize delegate;
and in the .h of the view where the popover appears:
#interface exampleViewController : UIViewController <OptionsViewControllerDelegate,UIPopoverControllerDelegate>{
UIPopoverController *popoverController;
OptionsViewController *optionsViewController;
}
and in the .m:
#synthesize popoverController;
#synthesize optionsViewController;
-(BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController{
return NO;
}
[popoverController release];
[optionsViewController release];
In the ViewDidLoad, I have:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
optionsViewController =[[OptionsViewController alloc]init];
optionsViewController.delegate = self;
popoverController = [[UIPopoverController alloc] initWithContentViewController:optionsViewController];
popoverController.popoverContentSize = CGSizeMake(320, 216);
}
To present the popover, I use:
-(IBAction)showDecadePopover{
[popoverController presentPopoverFromRect:CGRectMake(150, 50, 150, 50) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
I'm probably missing something really obvious (that's why I gave so much of my code). Thanks so much!
Luke
Yep, simple fix. After you init the popoverController you need to set the exampleViewController as the delegate of it.
[popoverController setDelegate:self];
PS: What is the id delegate; floating after your OptionsViewControllerDelegate protocol definition for? Synthesizing delegate, which you already do, is all you need to create storage for it.

Delegate Not Working

I'm Trying to dismiss a popover and transfer data at the same time. I implemented a delegate DismissPopoverDelegate but it is failing to work. But there are no errors. If the save button is tapped it registers it and it completes the line after where it calls the delegate. But its not working...
AddEventViewController_iPad.h
#import <UIKit/UIKit.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
#import <EventKit/EventKit.h>
#import <EventKitUI/EventKitUI.h>
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
#import <Foundation/Foundation.h>
#import "AboutSme.h"
#import "dateViewPopOverViewController_iPad.h"
#import "addPersonViewControllerPopover_iPad.h"
#import "PreviousEventsTableViewControllerPopover_iPad.h"
#interface AddEventViewController_iPad : UIViewController <UITableViewDelegate, UITableViewDataSource, MFMailComposeViewControllerDelegate, UITextFieldDelegate, UIAlertViewDelegate,UIPopoverControllerDelegate,UINavigationControllerDelegate,UIPopoverControllerDelegate,ABPeoplePickerNavigationControllerDelegate, ABNewPersonViewControllerDelegate, DismissPopoverDelegate> {
UIPopoverController *pop;
AddEventViewController_iPad.m
- (IBAction) selectStartDate:(id) sender {
NSLog(#"Select start date");
dateViewPopOverViewController_iPad *dateViewPopOverViewController = [[dateViewPopOverViewController_iPad alloc] init];
popover2 = [[UIPopoverController alloc] initWithContentViewController:dateViewPopOverViewController];
popover2.delegate = self;
popover2.popoverContentSize = CGSizeMake(320, 460);
CGRect rect = CGRectMake(790, 170, 175, 300);
[popover2 presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
[dateViewPopOverViewController release];
/*
if (dateViewController == nil) {
dateViewController = [[DateViewController_iPad alloc] initWithNibName:#"DateViewController_iPad" bundle:nil];
}
[self presentModalViewController:dateViewController animated:YES];
[dateViewController retain];
*/
}
- (void) dismissWithData:(NSString *)data
{
NSLog(#"%#", data);
[pop dismissPopoverAnimated:YES];
[pop release];
}
dateViewPopOverViewController_iPad.h
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#protocol DismissPopoverDelegate <NSObject>
#required
- (void) dismissWithData:(NSString *)data;
#end
#interface dateViewPopOverViewController_iPad : UIViewController {
IBOutlet UIDatePicker *datePicker;
IBOutlet UISegmentedControl *segmentedBar;
IBOutlet UILabel *startLabel;
IBOutlet UILabel *endLabel;
IBOutlet UISwitch *allDaySwitch;
NSDate *startDate;
NSDate *endDate;
NSDate *now;
NSDateFormatter *dateFormatter;
id<DismissPopoverDelegate> delegate;
}
#property (retain) id delegate;
- (void) dismissWithData:(NSString *)data;
dateViewPopOverViewController_iPad.m
#implementation dateViewPopOverViewController_iPad
#synthesize startDate, endDate, datePicker, segmentedBar, startLabel, endLabel, now, allDaySwitch, delegate;
- (IBAction) save:(id)sender {
if ([self startDateIsValid] && [self endDateIsValid]) {
//[[self parentViewController] setDatesForEvent:startDate eventEndDate:endDate allDay:[allDaySwitch isOn]];
// [self dismissModalViewControllerAnimated:YES];
NSLog(#"works");
[self.delegate dismissWithData:#"Some text from popover"];
NSLog(#"works1");
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Ooops!" message:#"Please check the dates! Remember the end date must occur after the start date for the event to save." delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
You have a circular reference when including the .h files.
dateViewPopOverViewController_iPad.h includes AddEventViewController_iPad.h and AddEventViewController_iPad.h includes dateViewPopOverViewController_iPad.h, which will cause the compiler to raise an error.
One of the aims to use protocols is to avoid this kind of circular reference. Removing the dateViewPopOverViewController_iPad.h include from your AddEventViewController_iPad.h file might fix the problem
Your call to dismissPopoverAnimated will not trigger the call to the delegate. From Apple's UIPopoverDelegate documentation:
The popover controller does not call this method in response to programmatic calls to the dismissPopoverAnimated method. If you dismiss the popover programmatically, you should perform any cleanup actions immediately after calling the dismissPopoverAnimated method.