Incomplete #implementation Startscreen - iphone

I'm receiving an warning on the implentation Topscore line in the code under here:
#import <Twitter/Twitter.h>
#import <GameKit/GameKit.h>
#import <AVFoundation/AVAudioPlayer.h>
#import <AudioToolbox/AudioServices.h>
#interface Topscore ()
#property (strong, nonatomic) NSString *imageString;
#property (strong, nonatomic) NSString *urlString;
- (void)clearLabels;
#end
#implementation Topscore // Warning on this line
#synthesize count, date, urlString = _urlString, imageString = _imageString, delegate, Topscore, currentLeaderBoard, earnedAchievementCache;
Incomplete implementation
My startscreen.h header file looks like the code under here:
#interface Startscreen : UIViewController <AVAudioPlayerDelegate> {
AVAudioPlayer *audioPlayer;
}
- (IBAction)tweetTapped:(id)sender;
- (IBAction) startgame;
- (IBAction) showLeader;
- (IBAction) subScore;
- (IBAction) showLeader;
- (IBAction) addScore;
- (IBAction) settings;
-(IBAction)playSound:(id)sender;
-(IBAction)pause:(id)sender;
-(IBAction)stopmusic;
#end
Does anyone know whats wrong?

This just means that you have not implemented, or defined, all of the methods that you wrote in your header file. If you define each IBAction in your implementation file, this error will go away. For example:
- (IBAction)tweetTapped:(id)sender {
//Do whatever you want it do do here
}
Overall, the error warning just means that you need to define everything. Because it is just a warning, your app will still build and run anyway.

Related

Subclassing a subclass of UIImageView - Forward declaration errors

I have read question after question about people getting the same error as me, but I simply do not understand them, so before you go searching for duplicate questions, maybe someone can explain to me what I am doing wrong with this subclassing deal.
I have a subclass of UIImageView called swapView that I want to subclass to override the method -(void)count for special cases. I went to subclass this as I have any pre-existing UIKit class, but when I tried to build and run the project, I get this error:
Attempting to use the forward class 'swapView' as superclass of 'coinView'
I have tried putting both the #import statement of swapView and #class swapView in coinView.h and I've tried putting the import statement in coinView.m, but it refuses to build because of this continued error. If I move the import statement into the .m file, all references to the superclass's methods and properties, such as #property (nonatomic) int max; cause errors as well.
What am I doing wrong?
swapView.h
#import <UIKit/UIKit.h>
#import "ViewController.h"
#class ViewController;
#interface swapView : UIImageView
{
NSTimer* tmr;
}
#property (nonatomic) int current;
#property (nonatomic) int max;
#property (nonatomic, retain) UIImage* firstImage;
#property (nonatomic, retain) UIImage* secondImage;
#property (nonatomic) BOOL smallMax;
#property (nonatomic, retain) ViewController* pvc;
- (BOOL)testCollision:(CGPoint)point;
- (float)randomFloatBetween:(float)smallNumber bigNumber:(float)bigNumber;
#end
coinView.h
#import "swapView.h"
#class swapView;
#interface coinView : swapView
- (void)count;
- (void)move;
#end
For inheritance, the superclass MUST be inherited.
coinView.h
#import "swapView.h"
#interface coinView : swapView
- (void)count;
- (void)move;
#end
You're both forward declaring and importing ViewController.h in your swapView, which may cause compiler to complain.
swapView.h
#import <UIKit/UIKit.h>
#class ViewController
#interface swapView : UIImageView
.
.
.
#end

Is there anything wrong with my codes?

One of my app worked and crashed at thread0, step 35, mem address 0x00002c60
35 MyAppName 0x00002c60 0x1000 + 7264
So I called command atos to locate the crash point as below:
atos -arch armv6 -o MyAppName.app/MyAppName 0x00002c60
it returns
-[AppDelegate setGPictureArray1:] (in MyAppName) (AppDelegate.m:9)
I show all codes before the line
//AppDelegate.h
#import <UIKit/UIKit.h>
#import "RootViewController.h"
#class RootViewController;
#interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet RootViewController *rootViewController;
NSMutableArray * gPictureArray1;
NSMutableArray * gPictureArray2;
}
#property (nonatomic, retain) NSMutableArray * gPictureArray1;
#property (nonatomic, retain) NSMutableArray * gPictureArray2;
#property (nonatomic, retain) IBOutlet UIWindow *window;
#property (nonatomic, retain) RootViewController *rootViewController;
#end
//AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
#implementation AppDelegate
#synthesize window;
#synthesize rootViewController;
#synthesize gPictureArray1;//**it looks like the crash happens here**
#synthesize gPictureArray2;
I can find there is any problem.
Welcome any comment.
I would guess that either the value you are trying to set that property as is an invalid pointer (pointing to a deallocated instance) or that the existing value is invalid.
Create the following function in the implementation file and put a breakpoint in it so you can track who is calling the setter:
-(void)setGPictureArray1:(NSMutableArray*)array
{
[gPictureArray1 release];
gPictureArray1 = array;
[gPictureArray1 retain];
}
Each time it is called check the value of "array" and "gPictureArray1" to make sure it is pointing to something valid. If it is called too many times you can also use NSZombies:
http://www.cocoadev.com/index.pl?NSZombieEnabled

iPhone - class stop seeing superclass' reference

I have this class where I have something like this on .h
#interface myClass : UIImageView <UIGestureRecognizerDelegate>{
#public id referenceOne;
#public id referenceTwo;
}
#property (nonatomic,retain) id referenceOne;
#property (nonatomic,retain) id referenceTwo;
on .m I have
#synthesize referenceOne, referenceTwo;
This class has no delegate protocol.
I have other classes that are based on this one. For one of these classes I have defined a delegate protocol and have my implementation file like this:
#protocol MyBasedClassDelegate <NSObject>
#optional
- (void) doStuff;
#end
#interface MyBasedClass : myClass {
id<MyBasedClassDelegate> _delegate;
}
#property(nonatomic,assign) id<MyBasedClassDelegate> delegate;
and on .m I have
#synthesize delegate;
as soon as I have defined this MyBasedClassDelegate the class stopped seeing the referenceOne and referenceTwo ids inherited from myClass. Now Xcode says these are not declared. If I disable the protocol, it sees the references again.
Why is that and how do I solve that?
thanks.
You have an error here:
#interface MyBasedClass : myClass {
id<MyBasedClassDelegate> _delegate;
}
rename to
#interface MyBasedClass : myClass {
id<MyBasedClassDelegate> delegate;
}
OR
do #synthesize delegate = _delegate; instead
EDIT:
Works well for me
myClass.h
#import <Foundation/Foundation.h>
#interface myClass : UIImageView <UIGestureRecognizerDelegate> {
id referenceOne;
id referenceTwo;
}
#property (nonatomic,retain) id referenceOne;
#property (nonatomic,retain) id referenceTwo;
#end
myClass.m
#import "myClass.h"
#implementation myClass
#synthesize referenceOne, referenceTwo;
#end
MyBasedClass.h
#import <Foundation/Foundation.h>
#import "myClass.h"
#protocol MyBasedClassDelegate <NSObject>
#optional
- (void) doStuff;
#end
#interface MyBasedClass : myClass {
id<MyBasedClassDelegate> delegate;
}
#property(nonatomic,assign) id<MyBasedClassDelegate> delegate;
#end
MyBasedClass.m
#import "MyBasedClass.h"
#implementation MyBasedClass
#synthesize delegate;
-(void) dosmth {
referenceOne = nil;
}
#end
If you change the variable name "_delegate" to "delegate", I think it might work. (Alternatively, comment out the synthesize line and it should also work).
I ran into a similar thing earlier today -- if you synthesize properties for instance variables that do not exist, the compiler doesn't complain but for some reason you can no longer see the superclass's variables.
For me it was finding http://www.iphonedevsdk.com/forum/iphone-sdk-development/53261-unable-access-superclass-member-variables-subclass-implementation.html that helped.

Error with custom Class definition in protocol

I'm trying to set up a custom delegate protocol and am getting a strange error that I don't understand. I wonder if someone could point out what I'm doing wrong here (I'm still new to Ob-C and protocol use)...
The situation is that I've built my own URLLoader class to manage loading and parsing data from the internet. I'm now trying to set up a protocol for delegates to implement that will respond to the URLLoader's events. So, below is my protocol...
#import <UIKit/UIKit.h>
#import "URLLoader.h"
/**
* Protocol for delegates that will respond to a load.
*/
#protocol URLLoadResponder <NSObject>
- (void)loadDidComplete:(URLLoader *)loader;
- (void)loadDidFail:(URLLoader *)loader withError:(NSString *)error;
#end
However, I'm getting the following error for both method signatures:
Expected ')' before 'URLLoader'
I feel like I must be overlooking something small and silly. Any help folks could offer would be greatly appreciated!
Whoops ... it was pointed out that I should include URLLoader.h. Here it is:
#import <Foundation/Foundation.h>
#import "URLLoadResponder.h"
/**
* URLLoader inferface.
*/
#interface URLLoader : NSObject {
NSString *name;
NSString *loadedData;
NSMutableData *responseData;
NSObject *delegate;
BOOL _isLoaded;
}
#property (nonatomic, retain) NSString *name;
#property (nonatomic, retain) NSString *loadedData;
#property (nonatomic, retain) NSObject *delegate;
- (void)loadFromURL:(NSString *)url;
- (void)addCompleteListener:(id)observer selector:(SEL)sel;
- (void)removeCompleteListener:(id)observer;
- (void)parseLoadedData:(NSString *)data;
- (void)complete;
- (void)close;
- (BOOL)isLoaded;
+ (NSURL *)makeUrlWithString:(NSString *)url;
+ (URLLoader *)initWithName:(NSString *)name;
#end
You have a nice circular reference in your headers, because each header include the other (URLLoader includes URLLoadResponder and URLLoadResponder includes `URLLoader).
You can break it by using a forward declaration:
#import <UIKit/UIKit.h>
//#import "URLLoader.h" <-- Remove it to break the circular reference
#class URLLoader; // <-- Forward declaration
/**
* Protocol for delegates that will respond to a load.
*/
#protocol URLLoadResponder <NSObject>
- (void)loadDidComplete:(URLLoader *)loader;
- (void)loadDidFail:(URLLoader *)loader withError:(NSString *)error;
#end

Properly declare delegation in Objective C (iPhone)

Ok, This has been explained a few times (I got most of the way there using this post on SO), but I am missing something. I am able to compile cleanly, and able to set the delegate as well as call methods from the delegate, but I'm getting a warning on build:
No definition of protocol 'DetailViewControllerDelegate' is found
I have a DetailViewController and a RootViewController only. I am calling a method in RootViewController from DetailViewController. I have the delegate set up as so:
In RootViewController.h:
#import "DetailViewController.h"
#interface RootViewController : UITableViewController <NSFetchedResultsControllerDelegate, DetailViewControllerDelegate> //Error shows up here
{
//Some Stuff Here
}
//Some other stuff here
#end
In RootViewController.m I define the delegate when I create the view using detailViewController.delegate = self
In DetailViewController.h:
#protocol DetailViewControllerDelegate;
#import "RootViewController.h"
#interface DetailViewController : UITableViewController <UITextFieldDelegate>
{
id <DetailViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <DetailViewControllerDelegate> delegate;
#end
#protocol DetailViewControllerDelegate
//some methods that reside in RootViewController.m
#end
I feel weird about declaring the protocol above the import in DetailViewController.h, but if I don't it doesn't build. Like I said, the methods are called fine, and there are no other errors going on. What am I missing here?
pheelicks is pretty much there but it looks like some of your protocol methods also use the DetailViewController class, I imagine it looks something like this :
#protocol DetailViewControllerDelegate <NSObject>
- (void) controller:(DetailViewController *)controller hasSomething:(id)thing;
#end
#class DetailViewController : UITableViewController <UITextFieldDelegate> {
id <DetailViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <DetailViewControllerDelegate> delegate;
#end
and you haven't defined DetailViewController yet so you will get an error in the protocol definition.
You can fix this in two ways :
a) Declare (but don't define yet) the class before the protocol
#class DetailViewController;
#protocol DetailViewControllerDelegate <NSObject>
- (void) controller:(DetailViewController *)controller hasSomething:(id)thing;
#end
b) Just use UITableViewController instead of DetailViewController in your protocol methods.
#protocol DetailViewControllerDelegate <NSObject>
- (void) controller:(UITableViewController *)controller hasSomething:(id)thing;
#end
Personally, I choose solution (a) but it really depends on what you're trying to do.
Hope that helps.
Try:
In DetailViewController.h:
#import "RootViewController.h"
#protocol DetailViewControllerDelegate <NSObject>
//some methods that reside in RootViewController.m
#end
#interface DetailViewController : UITableViewController <UITextFieldDelegate>
{
id <DetailViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <DetailViewControllerDelegate> delegate;
#end
Here is another way that you could tackle this, similar to the solution proposed by deanWombourne.
#protocol DetailViewControllerDelegate;
#interface DetailViewController : UITableViewController <UITextFieldDelegate> {
id <DetailViewControllerDelegate> delegate;
}
#property (nonatomic, assign) id <DetailViewControllerDelegate> delegate;
#end
#protocol DetailViewControllerDelegate <NSObject>
- (void) controller:(DetailViewController *)controller hasSomething:(id)thing;
#end