Unknown type name UITableView - ios

I am trying to use a library for drop down.When I copied its files in my project , I am getting weird error saying Unknown type name UITableView and also a lot of errors like Expected a type.What is wrong here?
#protocol kDropDownListViewDelegate;
#interface DropDownListView : UIView<UITableViewDataSource,UITableViewDelegate>
{
UITableView *_kTableView;
NSString *_kTitleText;
NSArray *_kDropDownOption;
CGFloat R,G,B,A;
BOOL isMultipleSelection;
}
#property(nonatomic,strong)NSMutableArray *arryData;
#property (nonatomic, assign) id<kDropDownListViewDelegate> delegate;
- (void)fadeOut;
// The options is a NSArray, contain some NSDictionaries, the NSDictionary contain 2 keys, one is "img", another is "text".
- (id)initWithTitle:(NSString *)aTitle options:(NSArray *)aOptions xy:(CGPoint)point size:(CGSize)size isMultiple:(BOOL)isMultiple;
// If animated is YES, PopListView will be appeared with FadeIn effect.
- (void)showInView:(UIView *)aView animated:(BOOL)animated;
-(void)SetBackGroundDropDwon_R:(CGFloat)r G:(CGFloat)g B:(CGFloat)b alpha:(CGFloat)alph;
#end
#protocol kDropDownListViewDelegate <NSObject>
- (void)DropDownListView:(DropDownListView *)dropdownListView didSelectedIndex:(NSInteger)anIndex;
- (void)DropDownListView:(DropDownListView *)dropdownListView Datalist:(NSMutableArray*)ArryData;
- (void)DropDownListViewDidCancel;
#end

You've missed an #import; probably:
#import <UIKit/UIKit.h>
This is normally part of the prefix file (pre-compiled header) so it's possible that is broken in some way.

Related

Why do I get Method definition for ... not found error after refactoring?

I have a very small class with an enum in the .h file, and that's it. I recently refactored the name of the .h file and for some reason the .m file names didn't refactor, so I had to change it manually. Now everything works as intended, but I suddenly get a warning on my #implementation in my .m file: Method definition for ... not found. Not sure why.
It looks like this in .m:
#import "TabTypeEnum.h"
#interface TabTypeEnum ()
#end
#implementation TabTypeEnum
- (void)viewDidLoad {
[super viewDidLoad];
}
#end
and in the .h
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
#interface TabTypeEnum : UIViewController
typedef enum {
MyTravels = 0,
Excursions,
Experiences,
Map,
Discover
} MyTabType;
- (void)myTabFunc: (MyTabType) myTab;
#end
NS_ASSUME_NONNULL_END
I didn't get the warning before, and all I did was change all the names to TabTypeEnum. I don't want to have the method implemented in the .m file. It's fine as it is.

Property Inheritance in Objective C

I want to inherit my base class properties and methods which will be used by my several derived classes. I want these properties and methods to be exactly protected so that they will only be visible in derived class and not to any external class. But it always gives me some errors.
#interface BasePerson : NSObject
#end
#interface BasePerson ()
#property (nonatomic, strong) NSMutableArray<Person*>* savedPersons;
#property (nonatomic) BOOL shouldSavePerson;
#end
#interface DerivedPerson1 : BasePerson
#end
#implementation DerivedPerson1
- (instancetype)init
{
if (self = [super init]) {
self.savedPersons = [NSMutableArray array];
self.shouldSavePerson = NO;
}
return self;
}
It always gives me an error that
Property 'savedPersons' not found on object of type 'DerivedPerson1 *'
Property 'shouldSavePerson' not found on object of type 'DerivedPerson1 *'
How i can make use of inheritance in Objective C, I don't want savedPersons and shouldSavePerson properties to be visible to external classes. I only want them to visible in my base class and all the derived classes.
Any help will be great. Thanks
This is not something that the objectiveC really support. There are some ways though. So lets see.
If you put a property in the source file class extension then it is not exposed and you can not access it in the subclass either.
One way is to put all of the subclasses into the same source file as the base class. This is not a good solution at all as you do want to have separate files for separate classes.
It seems logical to import the BaseClass.m in the SubClass source file but that will produce a linker error saying that you have duplicate symbols.
And the solution:
Separate the extension into a separate header. So you have a MyClass
Header:
#import <Foundation/Foundation.h>
#interface MyClass : NSObject
#end
Source:
#import "MyClass.h"
#import "MyClassProtected.h"
#implementation MyClass
- (void)foo {
self.someProperty = #"Some text from base class";
}
#end
Then you create another header file (only the header) MyClassProtected.h which has the following:
#import "MyClass.h"
#interface MyClass ()
#property (nonatomic, strong) NSString *someProperty;
#end
And the subclass MyClassSubclass
Header:
#import "MyClass.h"
#interface MyClassSubclass : MyClass
#end
And the source:
#import "MyClassSubclass.h"
#import "MyClassProtected.h"
#implementation MyClassSubclass
- (void)foo {
self.someProperty = #"We can set it here as well";
}
#end
So now if the user MyClassSubclass he will not have the access to the protected property which is essentially what you want. But the downside is the user may still import MyClassProtected.h after which he will have the access to the property.
Objective-C doesn't have member access control for methods, but you can emulate it using header files.
BasePerson.h
#interface BasePerson : NSObject
#property (strong,nonatomic) SomeClass *somePublicProperty;
-(void) somePublicMethod;
#end
BasePerson-Private.h
#import "BasePerson.h"
#interface BasePerson ()
#property (nonatomic, strong) NSMutableArray<Person*>* savedPersons;
#property (nonatomic) BOOL shouldSavePerson;
#end
BasePerson.m
#import "BasePerson-Private.h"
...
DerivedPerson1.h
#import "BasePerson-Private.h"
#inteface DerivedPerson1 : BasePerson
...
#end
Now any class that #imports BasePerson.h will only see the public methods. As I said though, this is only emulating access control since if a class #imports *BasePerson-Private.h" they will see the private members; this is just how C/Objective-C is.
We can achieve using #protected access specifier
#interface BasePerson : NSObject {
#protected NSMutableArray *savedPersons;
#protected BOOL shouldSavePerson;
}
DerivedPerson1.m
#implementation DerivedPerson1
- (instancetype)init
{
if (self = [super init]) {
self->savedPersons = [NSMutableArray array];
self->shouldSavePerson = NO;
}
return self;
}
#end
OtherClass.m
#import "OtherClass.h"
#import "BasePerson.h"
#implementation OtherClass
- (void)awakeFromNib {
BasePerson *base = [[BasePerson alloc]init];
base->savedPersons = #[];//Getting Error. Because it is not a subclass.
}
#end

Unknown types name UIBezierPath

I plan to make a QRBar scanner, I found a source called "IOS7_BarcodeScanner" which implement the any types of scanner to be used. I try the demo sources, and it works like a charm. But when I comes to creating my own project, and implement it. Unknown types name UIBezierPath, even I copy and paste exactly the files from demo source. It doesn't work. I have import the frameworks accordingly.
Barcode.h
#import <Foundation/Foundation.h>
#import AVFoundation;
#interface Barcode : NSObject
+ (Barcode * )processMetadataObject:(AVMetadataMachineReadableCodeObject*) code;
- (NSString *) getBarcodeType;
- (NSString *) getBarcodeData;
- (void) printBarcodeData;
#end
Barcode.m
#import "Barcode.h"
#interface Barcode()
#property (nonatomic, strong) UIBezierPath *cornersPath;
#end
#implementation Barcode
#end
Error
#property (nonatomic, strong) UIBezierPath *cornersPath;
Message
Unknown type name 'UIBezierPath'
Property with 'retain (or strong)' attribute must be of object type'
Import UIKit framework
Objective-C :
#import <UIKit/UIKit.h> OR #import UIKit;
Swift
import UIKit
Try adding this at the top of your .h file:
#import <UIKit/UIKit.h>

Parse Issue in Xcode 4.6.3 - "Expected a type" - Can't find the error

I have a Problem with Xcode:
At the moment I am working on an application for iOS SDK 6.1. Somedays ago I was implementing some methods and tried to compile the project.
Then something strange happened:
Compilation failed and I got some errors (see picture below) in two files, which aren't related to the methods I worked on.
I searched for errors in my code but couldn't find any.
Then I closed the project and opened it again: They were still here.
Then I closed the project and Xcode and reopened both: They were still here.
Then I created a new project and copied all the code: The issue appeared again.
Now I am stuck and have no clue what to do. Do I miss something in my code?
Please help me!
---
EDIT 1:
Here are some code snippets, which should show my code after I followed the suggestions of Martin R:
// PlayingCardDeck.h
#class PlayingCard;
#interface PlayingCardDeck : NSObject
- (void) addCard: (PlayingCard *) card atTop: (BOOL) atTop;
- (PlayingCard *) drawRandomCard;
- (BOOL) containsCard: (PlayingCard *) card;
- (BOOL) isCardUsed: (PlayingCard *) card;
- (void) drawSpecificCard: (PlayingCard *) card;
- (void) reset;
#end
// PlayingCardDeck.m
#import "PlayingCardDeck.h"
#interface PlayingCardDeck()
// PlayingCard.h
#import <Foundation/Foundation.h>
#import "RobinsConstants.h"
#import "PlayingCardDeck.h"
//#class PlayingCardDeck;
#interface PlayingCard : NSObject
+ (NSArray*) suitStrings;
+ (NSArray*) rankStrings;
+ (NSUInteger) maxRank;
- (id)initCardWithRank: (NSUInteger) r andSuit: (NSString*) s;
- (NSString*) description;
- (NSUInteger) pokerEvalRankWithDeck: (PlayingCardDeck *) deck;
- (NSAttributedString *) attributedContents;
- (BOOL) isEqual:(PlayingCard*)object;
#property (strong, nonatomic) NSString *contents;
#property (nonatomic, getter = isUsed) BOOL used;
#property (nonatomic, readonly) NSInteger rank;
#property (nonatomic, readonly, strong) NSString * suit;
#end
// PlayingCard.m
#import "PlayingCard.h"
#interface PlayingCard()
That looks like a typical "import cycle":
// In PlayingCardDeck.h:
#import "PlayingCard.h"
// In PlayingCard.h:
#import "PlayingCardDeck.h"
Replacing one of the #import statements by #class should solve the problem, e.g.
// In PlayingCardDeck.h:
#class PlayingCard; // instead of #import "PlayingCard.h"
And in the implementation file you have to import the full interface:
// In PlayingCardDeck.m:
#import "PlayingCardDeck.h"
#import "PlayingCard.h" // <-- add this one
There is something wrong in PlayingCard.h. This error causes the compiler to not know what a "PlayingCard *" is.
Can you show the code from PlayingCard.h?
Make sure the PlayingCard.m is added to your applications target! I would think it isn't (click the .m file and check your apps target in the inspector window on the right side pane)

trouble implementing method from inherited class -ios

I have looked through the other topics on this matter and I have not been able to determine my error.
I am very new to IOS programming. I am trying to create a program that looks at the selected state of 2 buttons and determines whether the buttons selected state are the same.
I am currently trying to use a model to determine the buttons selected state and then pass the state to a label. I have an error which says:
No visible #interface for 'MatchTest' declares the selector 'doesItMatch'
I'd appreciate any help that may be offered.
Thanks!
this is the MatchTest.h file
// MatchTest.h
#import <Foundation/Foundation.h>
#interface MatchTest : NSObject
#end
this is the MatchTest.m file
// MatchTest.m
#import "MatchTest.h"
#implementation MatchTest
-(NSString*)doesItMatch:(UIButton *)sender
{
NSString* tempString;
if(sender.isSelected)
{
tempString = #"selected";
}
else
{
tempString = #"not selected";
}
return tempString;
}
#end
this is the MatchViewController.h file
// MatchViewController.h
#import <UIKit/UIKit.h>
#import "MatchTest.h"
#interface MatchViewController : UIViewController
#end
this is the MatchViewController.m file
// MatchViewController.m
#import "MatchViewController.h"
#interface MatchViewController ()
#property (weak, nonatomic) IBOutlet UILabel *matchLabel;
#property (strong, nonatomic) MatchTest *match;
#end
#implementation MatchViewController
-(MatchTest *)match
{
if(!_match) _match = [[MatchTest alloc] init];
return _match;
}
- (IBAction)button:(UIButton *)sender
{
sender.selected = !sender.isSelected;
self.matchLabel.text = [self.match doesItMatch:sender];
}
#end
declare doesItMatch method in MatchTest.h file
like
in MatchTest.h
-(NSString*)doesItMatch:(UIButton *)sender;
compiler is not able to file doesItMatch method's declaration in .h file that's why that error is there.
You have not defined your method -(NSString*)doesItMatch:(UIButton *)sender in MatchTest.h file.
You are importing MatchTest.h file in MatchViewController.h file so you need to define your methods or variables or property to make available this method.
Therefore according to your error log viewController wasn't able to find the interface where this method is declared.

Resources