I have a warning message when I load Game Center Leaderboards with:
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
if (leaderboardController != nil) {
leaderboardController.leaderboardDelegate = self;
[self presentModalViewController:leaderboardController animated:YES];
}
Warning massage appears in third line, and It says:
warning: Semantic Issue: Assigning to
'id' from incompatible type
'ViewMenuController *'
I understand the message but I don't know how solve it.
The code works fine, but I would like remove the warning or find if there is a better way to load leaderboards.
Thanks in advance.
Solution:
I have done two modifications in ViewMenuController.h:
Add this import:
#import <GameKit/GameKit.h>
and modify this line adding :
#interface ViewMenuController : UIViewController <GKLeaderboardViewControllerDelegate> {
Thanks everybody for your help!
Best guess is when you are setting the leaderboardDelegate to self, it is expecting a id<GKLeaderboardViewControllerDelegate>, but your ViewMenuController does not define itself as conforming to the GKLeaderboardViewControllerDelegate protocol.
Make sure you set this in the interface of ViewMenuController.
Related
EDIT: I apologize for wasting time, the erorr had nothing to do with what I'm taking about but rather some logic in my code that made me believe this was the cause. I'm awarding Kevin with the correct answer since using his idea to pass the whole AuthorSelectionView, and his note on correcting the NSNumer mistake. Sorry about that.
I've been trying to figure this out for hours, and even left it alone for a day, and still can not figure it out...
My situation is as follows:
I've created a custom class that implements 'UIView' and made this class into a protocol as follows:
custom UIView h file
#protocol AuthorSelectionViewDelegate <NSObject>
-(void)AuthorSelected:(NSNumber *)sender;
#end
#import <UIKit/UIKit.h>
#interface AuthorSelectionView : UIView
#property (nonatomic,assign) id<AuthorSelectionViewDelegate> delegate;
#property (strong,retain) NSNumber *authorID;
- (id)initWithFrame:(CGRect)frame withImage:(UIImage *)img withLabel:(NSString *)lbl withID:(int)authorID ;
#end
the implementation...
- (id)initWithFrame:(CGRect)frame withImage:(UIImage *)img withLabel:(NSString *)lbl withID:(int)authorID
{
self = [super initWithFrame:frame];
if (self) {
self.authorID = [[NSNumber alloc] initWithInt:authorID]; //used to distinguish multiple instances of this class in a view.
...
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, FRAMEWIDTH, FRAMEHEIGHT)];
[button addTarget:self action:#selector(CUSTOMBUTTONCLICK) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];
}
return self;
}
- (void) CUSTOMBUTTONCLICK
{
[self.delegate performSelector:#selector(AuthorSelected:) withObject:self.authorID];
}
Now the method in my delegate object gets called just fine, but my major problem here is that something is going on with the object being pass through when i have multiple instances of the AuthorSelected class alloc'd.. (the NSNumber authorID). I'm getting some weird behavior with it. It seems almost random with the value being passed, but i'm detecting some pattern where the value passed through is coming up late..
thats confusing so ill try to explain:
I create two instances of the AuthorSelected view, one with authorID=1 and the other with authorID=2.
On the first press, lets say i press the first button, i'll get 1 as expected.
On the second press, if I press the 1st custom button, i'll get '1', but if i press the second i'll still get 1.
On the third go, either button will give me back '2'
I feel like this is some issue with pointers since that has always been a weak point for me, but any help would be greatly appreciated as I can not seem to figure this one out.
Thank you!
EDIT:
as requested here is how I create the AuthorSelectionView Objects...
AuthorSelectionView * asView01 = [[AuthorSelectionView alloc]
initWithFrame:CGRectMake(0, 0, FRAMEWIDTH, FRAMEHEIGHT)
withImage:userPic1
withLabel:randomUserName
withID:1];
asView01.delegate = self;
AuthorSelectionView * asView02 = [[AuthorSelectionView alloc]
initWithFrame:CGRectMake(0, 0, FRAMEWIDTH, FRAMEHEIGHT)
withImage:userPic2
withLabel:randomUserName2
withID:2];
asView02.delegate = self;
A detail that may be important:
As soon as i click on one of these custom views, my code is set to (for now) call the method that runs the above AuthorSelectionView alloc code, so that i can refresh the screen with the same layout, but with different userpic/userName. This is poor design, I know, but for now I just want the basic features to work, and will then worry about redrawing. I metion this tidbit, becuase I understand that objective-c 'layers' veiws on top of eachother like paint on a canvas, and had a thought that maybe when I click what I think may be my 2nd button, its really 'clicking' the layer beneath and pulling incorrect info.
Your description of the problem is a bit confusing, but this line in your init is very clearly wrong:
self.authorID = [self.authorID initWithInt:authorID];
In -init, your property self.authorID defaults to nil, so the expression [self.authorID initWithInt:authorID] is equivalent to [nil initWithInt:authorID], which evaluates back to nil. So you should actually be seeing nil in your action. You probably meant to say self.authorID = [NSNumber numberWithInt:authorID]
You're missing the alloc message, so this message:
self.authorID = [self.authorID initWithInt:authorID];
Is sent to a nil target, because self.authorID hasn't been allocated yet.
So first allocate it, then use the init method, or mix these two messages. A faster syntax allows to do it this way:
self.authorID= #(authorID);
EDIT
I don't see where you initialize the delegate, that method shouldn't even be called if you haven't initialized it. Show the code where you create the AuthorSelectionView objects and set the delegates.
instead of :
self.authorID = [self.authorID initWithInt:authorID];
put :
self.authorID = [NSNumber numberWithInt:authorID];
or
self.authorID = [[NSNumber alloc] initWithInt:authorID];
EDIT :
Don't you have errors or warnings in your code ? I can't see you returning self object in the init method ("return self;")
I got a question about subclassing.
I start with my first view:
in my .h file:
#interface viewAController : UIViewController
in my .m file:
-(void)viewDidLoad
{
[super viewDidLoad];
NSLog(#"Begin view");
udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *error = nil;
if (![udpSocket bindToPort:12345 error:&error]) //check ff of dit werkt!
{
NSLog(#"F you");
return;
}
NSLog(#"Derde line");
if (![udpSocket beginReceiving:&error])
{
NSLog(#"Screw you!");
return;
}
}
Porting and beginreceiving goes well.
and then when I subclass viewAController:
#interface viewBController : viewAController
in my .m file:
-(void)viewDidLoad{
[super viewDidLoad];
}
I am expecting that my subclass [viewBController], will display all of the NSLogs, because Im calling the super viewDidLoad.
Instead it is saying: F you!
Oke I understand that I can only bind once to the port, BUT Im expecting an error message, this does not show.
So I delete the binding and then I get Screw you, apparently I cannot say beginreceiving when Im not binding to a port. Without these two methods it works just fine though, it is printing everything out of the parent.
QUESTIONS:
Should I bind? I actually only need to listen to port 12345, should I just implement this differently?
Should I work without bind and without beginreceiving? I think I prefer with binding so that I wont listen to all of my ports.
Why cant I do beginreceiving when I dont bind?
How can I show the error?? Cause it is not printing any errors ...
greetz
What you are doing is right.But i have only one question to ask whether you have added the object of derived ViewController to some View.
Unless you wont add it you wont get the didLoad Of your superclass get fired.
Check by adding the object of your derived View to SomeView.
This is wrong you are doing
NSLog("#Hi there!");
you have to use
NSLog(#"Hi there!");
And if this is a typo (I hope it is) you have to add your sub class to some where using add subview or pushing it.
I am guessing this is a basic error... but can't seem to figure out the following build error (warning)...
Passing 'MessageDetailController *const __strong' to parameter of incompatible type 'id<MFMessageComposeViewControllerDelegate>'
On the following line...
controller.messageComposeDelegate = self;
I have the following declared in the header file...
#interface MessageDetailController : UIViewController <MFMailComposeViewControllerDelegate>
You could also try this line of code
controller.mailComposeDelegate = (id)self;
Try This
controller.mailComposeDelegate = self;
instead of controller.messageComposeDelegate = self;
because you have imported the MFMailComposeViewControllerDelegate protocol and i think you are trying to send the mail.
if i am wrong i.e you are trying to send the Message then you should Adopt the MFMessageComposeViewControllerDelegate Protocol,In this case no need to change the single line of code.
For more detailed Knowledge of MessageUI Framework take a look of this Link
I have this code what did I do wrong in it cause debugger in xCode is saying #implementation context heres my code below Thanks if you can help me fix right way or suggest what I should do. There error is there on the line TransitionOne
-(IBAction)Transition1:(id)sender
{
TransitionOne *view2 = [[transitionOne alloc] initWithNicName:#"TransitonOne" bundle:nil];
view2.modalTransitionStyle=UIModalTransitionStyleCoverVertical; // code
[self presentModalViewController:view2 animate:YES];
}
It's just a typo: try initWithNibName instead of initWithNicName. Because you had the method name wrong, the compiler thinks you are referring to a new method that had not been defined.
I'm hitting a wall over and over again, trying to solve a problem I've got in xcode. I'm a newbie and started coding just a while ago.
I'm trying to make a XML parser based on this tutorial: http://cocoadevblog.com/iphone-tutorial-creating-a-rss-feed-reader
which works fine separately, but when I'm implementing it into my own project, I get the 'NSInternalInconsistencyException' error, as a result of the following code:
----File: Parser.m----
- (void)parserDidEndDocument:(NSXMLParser *)parser {
if ([_delegate respondsToSelector:#selector(parsedInformation::)]){
[_delegate parsedInformation:information];
}else{
[NSException raise:NSInternalInconsistencyException
format:#"Delegate (%d) doesn't respond to parsedInformation:", _delegate];
}
}
I've tried to remove the if-phrase, and then it calls the correct function, but the data which is supposed to be overhanded, won't get through.
Project setup
The project is a tab-based application. I'm having three classes:
Parser
AlphaTab
RootDelegate
In RootDelegate I used the following code to initialize the tab-view, and then to initialiaze the AlphaTab as a tableView being part of a navigationView:
----RootDelegate.m ----
tabBarController = [[UITabBarController alloc] init];
alphaTab = [[AlphaTab alloc] initWithTabTitle:#"AlphaTab" navigationTitle:#"Exploring"];
UINavigationController *tableNavController = [[[UINavigationController alloc] initWithRootViewController:alphaTab] autorelease];
tableNavController.delegate = self;
[alphaTab release]; // creates your table view's navigation controller, then adds the created view controller. Note I then let go of the view controller as the navigation controller now holds onto it for me. This saves memory.
So good so far.. the problem comes when I use the Parser class, which parses a given XML file. This class is initialized and only implemented in the AlphaTab - therefore it has nothing to do with the RootDelegate class at all. The initialization is done as:
----File AlphaTab.m ----
- (void)loadData{
if(information==nil){
Parser *XMLParser = [[Parser alloc] init];
[XMLParser parseFeed:#"http://frederikbrinck.com/bodil/Example.xml" withDelegate:self];
[XMLParser release];
}else {
[self.tableView reloadData];
}
}
I'm suspecting the parameter withDelegate's value "self" to be the problem, which I think referres to the super class RootDelegate, but I'm not sure. Likewise, I don't know to pass the AlphaTab class' delegate to the function, which I think would solve the problem.
I'm ought to think, that the problem could be created from this line aswell:
----FILE: Parser.h ----
#protocol AlphaTab <UITableViewDelegate>
- (void)parsedInformation:(NSArray *)i;
#end
I've done some research about protocols and respondsToSelector, but honestly, I didn't understand much, since my code is seen from the programmatic perspective of view, without using the InterfaceBuilder at all, since I've been adviced to do that. It hasn't lead to the solution of the problem either.
For further understanding, I then want this function in AlphaTab.m to be called, when the information is parsed.
----FILE AlphaTab.m ----
- (void)parsedInformation:(NSArray *)i {
NSLog(#"The parser has completed parsing");
information = i;
NSLog(#"This is the information: %d", [[information objectAtIndex:0] objectForKey:#"tabTitle"]);
[self.tableView reloadData];
}
I've looked on the net, and I found some explications about the NSInternalInconsistencyException. I've tried to do them as well, for example by setting everybody with themselves as delegates. However, I had no luck. What wonders me most, is that when I use the Parser without having to subclass it's caller (this case: AlphaTab) to a main class, it works like a charm.
I hope you guys can give me a clue. If you need any more information please ask, and I'll be in disposition.
//Brinck10
Please see #warrenm and his comment.