iPhone: Warning in Cyclic import in MKAnnotation: method not found - iphone

I just resolved a cyclic dependency problem by using class forwarding. Now, I am getting a warning of no 'showSumDetails' method found. I don't understand why it should happen at all, any help will be appreciated. Including a bit of code here:
MyAnnotation.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
//#import "MyMapViewController.h" obviously this wasn't possible :-(
#class MyMapViewController;
#interface MyAnnotation : NSObject<MKAnnotation> {
MyMapViewController* mapController;
}
MyMapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKReverseGeocoder.h>
#import "MyAnnotation.h"
#interface MyMapViewController : UIViewController <MKMapViewDelegate>{
MyAnnotation *annot;
}
MyMapViewController.m - where the method actually exists, and it is defined in the header file as well.
#implementation MyMapViewController
#synthesize annot;
-(void) showSumDetails:(id)aSumData{
NSLog(#"mapViewController-showSumDetails");
SumDetailsViewController *wrController = [[SumDetailsViewController alloc] init];
wrController.sumData = aSumData;
[self.navigationController pushViewController:wrController animated:YES];//This needs to be pushed
[wrController release];
}
#end
But the following method in MyAnnotation.m can't find the method above :-(
#implementation MyAnnotation
#synthesize sumData;
#synthesize mapController;
- (void) showPD{//is also defined in header file
NSLog(#"sPD - MyAnn");
[mapController showSumDetails:sumData]; //This doesn't have a clue about showSumDetails method- Why??
}
I'd be glad to provide any more info. Please help!!!

Did you import MyMapViewController.h in MyAnnotation.m?
Since you're using a forward reference for MyMapViewController in MyAnnotation.h you need to import MyMapViewController.h in MyAnnotation.m.

Related

" no known class method for selector ‘methodname’ " but my code is correct

no known class method for selector ‘Logout’
but I have try to create a new project with same code,it is work!
Why?
do anyone can answer me?
LoginController.h
//
// LoginController.h
//
#import <Foundation/Foundation.h>
#interface LoginController : NSObject
+(void)Logout;
#end
LoginController.m
//
// LoginController.m
//
#import "LoginController.h"
#implementation LoginController
+(void)Logout{
//something here
}
#end
HomeViewController.m
//
// HomeViewController.m
//
#import "LoginController.h"
#interface HomeViewController ()
#end
HomeViewController.m
#implementation HomeViewController
- (void)viewDidLoad
{
[LoginController Logout];
}
#end
You likely didn't #import "LoginController.h" in HomeViewController.m, so the compiler doesn't know about this method. It looks like you did include it in the .h, but you may not have included an #import "HomeViewController.h" in HomeViewController.m

Unknown type name 'XMLParser'; did you mean 'NSXMLParser'?

Why I get this error "Unknown type name 'XMLParser'; did you mean 'NSXMLParser'?" ? I have imported XMLParser.h, so I can't understand what the problem is.
#import <UIKit/UIKit.h>
#import "XMLParser.h"
#import "televisionList.h"
#import "ListingCell.h"
#interface TelevisionDetail : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
XMLParser *xmlParser;
}
#end
Seems like Xcode bug, but also it's a good practice to avoid unnecessary import in .h file.
So try to add this before #interface..:
#class XMLParser;
And add #import "XMLParser.h" in your .m file.

Cant call instance methods from other classes

I hope you can help me with the following problem in Objective-C. I´ve been sitting around for two hours now, but I have no idea what´s wrong.
Here´s my code:
BMICalc.h:
#import <UIKit/UIKit.h>
#interface BMICalc : UIViewController <UIPickerViewDataSource, UIPickerViewDelegate>
#property (strong, nonatomic) NSMutableArray *bmiArray;
-(int)bmiRows;
#end
BMICalc.m:
#import "BMICalc.h"
#implementation BMICalc
#synthesize bmiArray;
- (int) bmiRows
{
if (!bmiArray)
{
bmiArray = [[NSMutableArray alloc] init];
}
return [bmiArray count];
}
#end
Now I want to create a object of BMICalc in another class called BMIDiaryController:
BMIDiaryController.m:
#import "BMIDiaryController.h"
#import "BMICalc.h"
#interface BMIDiaryController ()
#end
#implementation BMIDiaryController
- (void)viewDidLoad
{
[super viewDidLoad];
BMICalc *bmiSender = [[BMICalc alloc] init];
int bmiVariable = [bmiSender bmiRows];
}
#end
So when I start the programme i get the following error:
"No visible #interface for 'BMICalc' declares the selector 'bmiRows'
I can´t call the method "bmiRows" with the object "bmiSender" (both of Class "BMICalc"
I hope you can help me with this. I searched and searched...I think it´s just a small thing, but I won´t see it...
Thank you and regards,
Stefan
Try creating a new project. Then add the BMICalc.m and BMICalc.h files. Try to instantiate your BMICalc object and call the bmiRows method from the appDelegate just to test it. There could be any number of things wrong in your main project that may be interfering with the class. At least doing this will confirm that you aren't crazy and that this code isn't the problem :)

UIViewController calling each other's delegate

I have two UIViewController, each has it's delegate and is calling one or the other. One class is called TopicViewController and the other is MentionViewController, the code looks something like the following:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <RestKit/RestKit.h>
#import "Message.h"
#import "Imgur.h"
#import "URLViewController.h"
#import "CVore.h"
#import "NSData+Base64.h"
#import "Imgur.h"
#import "ProfileViewController.h"
#import "OptionsViewController.h"
#import "Three20/Three20.h"
#class DetailViewController;
#class MentionViewController;
#protocol DetailViewControllerDelegate
- (void) viewController:(DetailViewController*)viewCon withText:(NSString *) text;
#end
#interface DetailViewController : UIViewController <MentionViewControllerDelegate>
///////////////////////////////////////////////////////////////////////////////////
#import <UIKit/UIKit.h>
#import <RestKit/RestKit.h>
#import "Members.h"
#import "DetailViewController.h"
#import "Three20/Three20.h"
#class MentionViewController;
#protocol MentionViewControllerDelegate
- (void) viewController:(MentionViewController*)viewCon withUsername:(NSString *) text;
#end
#interface MentionViewController : UITableViewController <DetailViewControllerDelegate>
Now the problem is that when I add #import "MentionViewController.h" to the DetailViewController it gives me the following error in the MentioViewController:
Cannot find protocol declaration for DetailViewControllerDelegate.
I understand this might be due to cylical referencing, but how do I solve this?
It is really strange. The MentionViewController needs the header file of DetailViewController, and the DetailViewController needs MentionViewController's header file. It is a cycle. Maybe you need to create a empty header file, and put all protocol inside it. For example,
MyProtocol.h
#class DetailViewController;
#class MentionViewController;
#protocol DetailViewControllerDelegate
- (void) viewController:(DetailViewController*)viewCon withText:(NSString *) text;
#end
#protocol MentionViewControllerDelegate
- (void) viewController:(MentionViewController*)viewCon withUsername:(NSString *) text;
#end
And add #import MyProtocol.h inside DetailViewController.h and MentionViewController.h.
You need to use forward declaration for the protocols and only import the headers in the implementation file.
I think your intuition is correct.
You should be able to solve this problem by declaring the 2 protocols in a header file of their own, then import this file from your .m files.
This will break the cycle.

Consequence of importing appDelegate in a class and the same class in appDelegate

I want to know the consequence of importing appDelegate in a class and the same class in appDelegate. Because, I'm doing this in my application successfully, but it's recommended that it should not be done. I couldn't find the answer despite a lot of searching.
Thanks in advance.
You can do it, but be careful with how you import headers. This is the recommended way:
AppDelegate.h:
// Import headers here
#class MyViewController;
#interface AppDelegate : NSObject <UIApplicationDelegate> {
MyViewController *viewController;
}
- (void)someMethod;
#end
AppDelegate.m:
#import "AppDelegate.h"
#import "MyViewController.h"
#implementation AppDelegate
//Your code here
#end
MyViewController.h:
// Import headers here
#class AppDelegate;
#interface MyViewController : UIViewController {
AppDelegate *appDelegate;
}
#end
MyViewController.m:
#import "MyViewController.h"
#import "AppDelegate.h"
#implementation MyViewController
// Your code here
#end
As you can see, you want to use #class to declare the classes in your headers, and then import the header in your .m files. This ensures that you’re not importing things that you don’t need; if you imported the view controller header in your app delegate’s header, it would be imported into anything that imported your app delegate’s header. By leaving all the imports to the .m files, you prevent that situation.