Objective C Properties - iphone

I tried searching for this issue, but can't seem to find out what I'm doing wrong.
Here is my controller header:
#import <UIKit/UIKit.h>
#interface BabyLearnViewController : UIViewController {
UIButton *btnImage;
MediaManager* myMediaManager;
}
#property (nonatomic, retain) IBOutlet UIButton *btnImage;
#property (retain) MediaManager* myMediaManager;
- (IBAction)setNewImage;
#end
Here is my controller class:
#import "BabyLearnViewController.h"
#import "MediaManager.h";
#implementation BabyLearnViewController
#synthesize btnImage;
#synthesize myMediaManager;
I am getting the errors:
error: expected specifier-qualifier-list before 'MediaManager'
error: no declaration of property 'myMediaManager' found in the interface
Any ideas? Usually the 1st error comes up if you have a cylical reference. 'MediaManager' doesn't reference anything else. Any ideas?

Since you have no mentions of MediaManager class at the moment it is used in header file compiler can't figure out what "MediaManager" is and issues an error. Declare that class using forward declaration in your header file to let compiler know that MediaManager is actually a class:
#class MediaManager;
#interface BabyLearnViewController : UIViewController {
...
P.S. As an alternative you can import MediaManager.h in your header, but using forward declaration is preferred.

Place #import "MediaManager.h"
this in header file of BabyLearnViewController

try add #class MediaManager; before #interface

Related

Unknown type name Error Iphone

It's giving the UNKNOWN TYPE NAME error. I had imported "billSummary" class as well, but don't know why xcode giving this error.
#import <UIKit/UIKit.h>
#import "customiseForItems.h"
#import "billSummary.h"
#interface itemsInParty : UITableViewController<UIAlertViewDelegate>{
IBOutlet customiseForItems *tblCell;
IBOutlet UIToolbar *billSummaryTool;
CGFloat percValue;
billSummary *billSummaryToShow; //ERROR UNKNOWN TYPE NAME BILL SUMMARY
UIAlertView *alertForPercentage;
NSMutableArray *selectedEntriesPath;
BOOL descTapped;
}
Write #class billSummary; instead of #import "billSummary.h"
Try like this it will be helpful to you.
one possible reason is:
billSummary.h
#interface billSummaryMisspelled : ParentClass
#end
billSummary.m
#implementation billSummaryMisspelled
#end
your file name != to you class name
you can use forward class declaration to skip the error,
#class billSummary;
instead of #import

My #property is declared yet I still get may not respond to warning

I don't like warnings lying around and this one has been bothering me. Any ideas on what I am doing wrong? I have tons of properties using this same approach and none of them are giving me warnings. Why doesn't Xcode recognize this one?
While the app works as expected, Xcode gives me the following compile time warning:
'OnlinePeerBrowser' may not respond to '-setMyParent:'
My property declaration in OnlinePeerBrowser.h
#import "WelcomeViewController.h"
#interface OnlinePeerBrowser : UIViewController <UITableViewDelegate, UITableViewDataSource, NSNetServiceBrowserDelegate> {
WelcomeViewController *_myParent;
}
#property (nonatomic, assign) WelcomeViewController *myParent;
OnlinePeerBrowser.m has
#synthesize myParent=_myParent;
I am getting the warning on setMyParent in WelcomeViewController.m here...
#import "WelcomeViewController.h"
#import "OnlinePeerBrowser.h"
#implementation WelcomeViewController
- (void)peerPickerController:(GKPeerPickerController *)picker didSelectConnectionType:(GKPeerPickerConnectionType)type {
...
OnlinePeerBrowser *controller = [[OnlinePeerBrowser alloc]
initWithNibName:#"OnlinePeerBrowser" bundle:nil];
[controller setMyParent:self];
}
Also, what is weird is that I can not use the dot syntax here either.
controller.myParent = self;
gives me the following error:
/Users/vesselhead/Development/iPhone/DJBox/WelcomeViewController.m:254: error: request for member 'myParent' in something not a structure or union
I feel like I must be missing something very simple.
The code you've posted looks correct. That means that the compiler is pulling in another declaration of the OnlinePeerBrowser class from somewhere.
Check for circular imports.
Check if you have multiple copies of the OnlinePeerBrowser.h file.
Add the line #warning Testing to your OnlinePeerBrowser.h file. That warning should then appear in the log when you compile. If that warning doesn't appear then that file isn't being picked up by the compiler.
If it's a circular import then don't import "WelcomeViewController.h" in "OnlinePeerBrowser.h". Instead, use a forward declaration in OnlinePeerBrowser.h, e.g. #class WelcomeViewController , and import "WelcomeViewController.h" in OnlinePeerBrowser.m
Sometimes Circular Imports create an issue with the compiler.
Instead of using
#import "WelcomeViewController.h"
in OnlinePeerBrowser.h move that line to the OnlinePeerBrowser.m and add
#class WelcomeViewController
to the OnlinePeerBrowser.h
this will allow you to set the Class of myParent and _myParent to WelcomeViewController and not have the Circular Import.
Alternatively:
you may want to use a #protocol that the WeclomeViewController would have to adhere to. Then you would only have to import the Classes in one direction.
the implementation for a Protocol property would be as Follows
//#import "WelcomeViewController.h"
#protocol OnlinePeerBrowserParent <NSObject>
#required
- (NSString*) informationFromParent;
#end
#interface OnlinePeerBrowser : UIViewController <UITableViewDelegate, UITableViewDataSource, NSNetServiceBrowserDelegate> {
id<OnlinePeerBrowserParent> _myParent;
}
#property (nonatomic, assign) id<OnlinePeerBrowserParent> myParent;
notice the Protocol is on the OnlinePeerBrowser.h so you can import the OnlinePeerBrowser.h and get the Protocol by default.
finally you implement the Protocol in the WelcomeViewController as so
#implementation WelcomeViewController<OnlinePeerBrowserParent>
- (NSString*) informationFromParent
{
return #"My Parental Info";
}
...... etc

cannot find protocol declaration custom protocol delegate iphone

Slowly but surely getting this delegation and protocol stuff on iphone but I cannot understand this error.
I have declared my protocol in my first viewcontroller.
In the second viewcontroller i try to add it at the top after i have imported it into the header file and it cannot find it. see my code below.
//SendSMS
#import <UIKit/UIKit.h>
#import "LoginPage.h"
#import "MessageOptions.h"
#protocol SMSProtocol <NSObject>
-(NSString *)postbackType;
#end
#interface SendSMS : UIViewController <UITextViewDelegate, UITextFieldDelegate> {
id<SMSProtocol> delegate;
MessageOptions *messageOptions;
LoginPage *loginPage;
IBOutlet UITextField *phonenumber;
IBOutlet UITextView *smsBody;
IBOutlet UIScrollView *scrollview;
}
#property (nonatomic, retain) id<SMSProtocol> delegate;
-(IBAction)LoadMessageOptions;
#end
Then my second view
#import <UIKit/UIKit.h>
#import "SendSMS.h"
#interface ScheduledSMS : UIViewController <SMSProtocol>{
}
-(IBAction)popBack;
#end
That is surely strange. Have you tried restarting Xcode? Xcode has a habit of not indexing symbols for me when I add new files.
You should also look into how your naming conventions. SendSMS is not really a good class name, more of a action method name. I would go for SendSMSViewController, since that is what it is.
By that it would follow that SMSProtocol should be named SendSMSViewControllerDelegate, since that is what it is.
Methods in a delegate protocol should contain the sender and one of the three words will, did, or should. If not at the very least it should name what it expects to return. -(NSString *)postbackType; should probably be -(NSString *)postbackTypeForSendSMSViewController:(SendSMSViewController*)controller;.

error instantiating other view controllers

I am sure this is really dumb, but I just cant seem to understand why am I getting this error. In my project I have a view controller and another class that does some data structuring job (not relevant anyway). I am getting a compilation error: "unknown type name "the view controller"" when trying to instantiate it within my class.
This is my class .h:
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
#import "MyLocationController.h"
#import "GetZip.h"
#import "SecondTab.h"
#interface DataEngine : NSObject <MyLocationControllerDelegate, MKMapViewDelegate, GetZipcodeDelegate> {
MyLocationController *CLController;
GetZip *getzip;
SecondTab *secondTab; //ERROR IS HERE
}
My view controller .h:
#import <UIKit/UIKit.h>
#import "FirstTab.h"
#import "DataEngine.h"
#interface SecondTab : UIViewController <UITableViewDelegate, UITableViewDataSource> {
IBOutlet UITableView *table1;
NSString *address;
NSDate *time;
NSDictionary *dataDict;
DataEngine *fullData;
}
(I omitted all the #synthesis since I dont think they matter...in any case, I do #property (nonatomic, retain) for everything).
Any idea what can go wrong here?
Why don't you try to forward declare it. Use #class secondTab instead of #import secondTab? It will help avoiding any circular inclusions if thats the problem.

class declaration Problem in IPhone SDk?

i have declared one class such as
#import "CalcEntryVC.h"
#interface initialcontroller : UIViewController<UINavigationControllerDelegate>
{
IBOutlet BookmarkListTVC *bkcontroller;
IBOutlet CalcEntryVC *calcentryVCController;
}
but when i declare in BookmarkListTVC.h
as
#interface BookmarkListTVC : UITableViewController <UIActionSheetDelegate,UINavigationBarDelegate>
{
IBOutlet CalcEntryVC *calcentryVCController;
}
the error comes error: expected specifier-qualifier-list before 'CalcEntryVC'
how can i overcome , i tried #ifndef also.....any solution pls?
you don't want to import the header as suggested in another answer. YOu want to use the #class directive to declare CalcEntry as a forward declaration:
#class CalcEntryVC.h
Have you done #import "CalcEntryVC.h" in BookmarkListTVC.h?