Accessing unknown 'view' component of a property - iphone

I get an 'Accessing unknown 'view' component of a property' error, when I'm trying this:
if (self.newsViewController.view.superview == nil)
I have a synthesize and an import for NewsViewController. What I'm doing wrong?

Unfortunately, SO won't let me comment on your post, but if that:
#interface newsViewController : UIViewController {
is actually copy & pasted, it might just be a typo (lowercase 'n' instead of uppercase in NewsViewController)?

Another problem might be absence of import...
http://shirishranjit.com/blog1/?p=132

Related

Multiple methods named 'tag' found with mismatched result

I have added GDataframework in my project ,after adding it,i am getting error
"Multiple methods named 'tag' found with mismatched result". If i remove GDataFramework than it works fine.Can i modify in GDataframework or should i have to done in my project ?
int buttonTag=[sender tag] //here that error prompts up at every place in my project
Is your code inside an action method, like this?
- (IBAction)buttonPressed:(id)sender {
int buttonTag = [sender tag];
}
Then you can solve the problem by replacing id with the correct type of the sender (UIButton * in this case):
- (IBAction)buttonPressed:(UIButton *)sender {
int buttonTag = [sender tag];
}
because the compiler then knows that sender is an instance of the UIButton class, and therefore knows which tag method is applied here.
Note that you can define the correct type already when creating the connection in Xcode:
This link has a problem similar to yours: Defeating the "multiple methods named 'xxx:' found" error Try to follow the guidelines the answer to this question does in your own app.
In one scenario, if the factory method that creates the object has return type "id" then the compiler will check the method signature in all the classes. If compiler find the same method signature in more than one class then it will raise the issue. So replace the return type "id" with "specific class name".

How do i refer to methods inside a UIVIiw?

I have imported my .h file into a 2nd one, but in the 2nd one i'm trying to do:
FirstClass *firstClass = [FirstClass alloc] init];
[firstClass iconWithType:test];
To match this:
-(void)iconWithType:(NSString *)iconType
But it's not listing iconWithType as a suggestion and i get a warning saying it might not respond to that.
How can i get this to work properly?
My FirstClass is a UIView.
In your FirstClass.h file do you have the method definition in the interface?
I.e.
#interface FirstClass : NSObject {
}
- (void)iconWithType:(NSString *)iconType;
#end
Additionally, the name of the method implies something should be returned. However, it is marked as void.
I'm guessing you just have a return type mismatch. Take a look: does -iconWithType: actually return void? or does it return a UIImage or something else besides?

Why is this pointer type incompatible

This is the code
Dest.h
#import <UIKit/UIKit.h>
#import <CoreGraphics/CGPDFArray.h>
#class Model;
// snip
#interface Dest : NSObject
{
CGPDFArrayRef destArray;
DestKind kind;
}
+ (id)destWithObject:(CGPDFObjectRef)obj inModel:(Model*)model;
- (id)initWithArray:(CGPDFArrayRef)array;
Dest.m
#implementation Dest
+ (id)destWithObject:(CGPDFObjectRef)obj inModel:(PDFModel*)model
{
CGPDFArrayRef array = NULL;
Dest* dest = nil;
// stuff to create array
if (array)
{
dest = [[[Dest alloc] initWithArray:array] autorelease];
<path>/Dest.m:63: warning: passing argument 1 of 'initWithArray:' from incompatible pointer type
}
return dest;
}
Clearly the compiler thinks that array is incompatible with initWithArray: declared in Dest.h. But as far as I can see, the type is exactly right. I even copied the declaration from Dest.h and pasted it in Dest.m. initWithArray: compiles fine. Adding/removing the CGPDFArray.h header file in Dest.h doesn't make any difference, the compiler doesn't think it is an int in Dest.h.
I have a feeling you're leaving out another warning that's relevant — "warning: multiple methods named 'initWithArray:' found". If I'm right, this is what you're running into:
There are two method signatures that go with that selector. NSArray's takes an NSArray* and yours takes a CGPDFArrayRef.
alloc returns id. This means that the compiler has no idea what class it returns (yes, the compiler is that thick).
You then send initWithArray: to this mystery object. The compiler says, "Gosh, I don't know what kind of object this is, so I can't decide which method signature is correct. I'll spin around really fast and whichever one I'm facing is the one I'll pick." It chooses NSArray's signature. Then it looks at the argument and says, "Hey, that's not an NSArray! Error!"
The quick-and-easy solution is to change it to [[(Dest*)[Dest alloc] initWithArray:array] autorelease]. The better solution is to choose a distinct selector for your method.
Oh don't do that. Only CFArrayRefs are 'toll-free bridged' to NSArray. The CGPDFArrayRef however is completely different and incompatible. You can not use those as NSArrays.
The PDF API sure looks like a standard Core Foundation compatible one, but it really is not.
From Apple's documentation,
CGPDFArray header file defines an
opaque type that encapsulates a PDF
array
so it cannot be used as a NSArray.

error: expected specifier-qualifier-list before 'SearchViewController'

i have a search view controller like below.
#interface SearchViewController : {
TopicRulesViewController *TViewController;
}
i want to move to another view.but i am getting this "error: expected specifier-qualifier-list before 'TopicRulesViewController'"
what is that error?
thanks in advance
You are missing a superclass after the :
You need to import header where TopicRulesViewController class is declared, or, even better - use forward declaration in header file and import necessary header in implementation file:
//header
#class TopicRulesViewController;
#interface SearchViewController : UIViewController{
TopicRulesViewController *TViewController;
}
//m-file
#import "TopicRulesViewController.h"
...
P.S. You also miss superclass for SearchViewController class, but that produces different compiler error so I assumed that that was just a typo...

Use of type 'id' in cocoa class

I want to implement a class which can be used by two classes of my project.
One is manipulating 'NewsRecord' objects.
One is manipulating 'GalleriesRecord' objects.
In another class, I may use one of the two objects so i do something like that :
// header class
id myNewsRecordOrGalleriesRecord;
// class.m
// NewsRecord and GalleriesRecord have both the title property
NSLog(myNewsRecordOrGalleriesRecord.title);
and i get :
error : request for member 'title' in something not a structure or union
any ideas :D ?
Thanks.
Gotye
How am I supposed to do it ?
You can't use dot syntax on id types because the compiler cannot know what x.foo means (the declared property may make the getter a different name, e.g. view.enabled -> [view isEnabled]).
Therefore, you need to use
[myNewsRecordOrGalleriesRecord title]
or
((NewsRecord*)myNewsRecordOrGalleriesRecord).title
If title and more stuffs are common properties of those two classes, you may want to declare a protocol.
#protocol Record
#property(retain,nonatomic) NSString* title;
...
#end
#interface NewsRecord : NSObject<Record> { ... }
...
#end
#interface GalleriesRecord : NSObject<Record> { ... }
...
#end
...
id<Record> myNewsRecordOrGalleriesRecord;
...
myNewsRecordOrGalleriesRecord.title; // fine, compiler knows the title property exists.
BTW, don't use NSLog(xxx);, which is prone to format-string attack and you can't be certain xxx is really an NSString. Use NSLog(#"%#", xxx); instead.
Try accessing the title of your record like [myNewsRecordOrGalleriesRecord title];
If you're going to be doing a lot of this type of thing (accessing common methods in two classes) you would probably benefit significantly from either creating an abstract superclass that both NewsRecord and GalleriesRecord can inherit from (if they'll be sharing a lot of code) or creating a protocol they both can adhere to (if they'll be sharing method names but not code.
The compiler is not happy since an id is actually a NSObject instance, which doesn't have a title property.
If your object is KVC compliant, you can use the valueForKey method:
NSLog( [myNewsRecordOrGalleriesRecord valueForKey:#"title"] );