Creating a FBProfilePictureView in Storyboard - objective-c

I created a UIView inside the main view of a view controller using the storyboard editor and changed its class to FBProfilePictureView.
I created an outlet:
#property (weak, nonatomic) IBOutlet FBProfilePictureView *userImage;
However, when I refer to the userImage object in code it reports itself as a UIView.
NSLog(#"userImage class: %#", [userImage class]);
Produces:
2012-08-28 17:52:22.196 FBTestApp[6230:707] userImage class: UIView
What am I missing?

While I didn't see the error mentioned in the FB docs, adding:
[FBProfilePictureView class];
To applicationDidFinishLaunching did the trick. Presumably some runtime magic going on.

I wouldn't rely on [userImage class] for anything other than calling class methods. If you need to ensure userImage is the correct type, use [userImage isKindOfClass:[FBProfilePictureView class]]. It will let you know if you can treat the object as a FBProfilePictureView.

A more elegant way to resolve this might be adding the -ObjC linker flag instead of doing this "runtime magic" stuff. Here you can find instructions on how to add the flag!
See the SDK documentation, which says:
Note: If you've added the -ObjC flag to your linker options, then you don't have to add this code. Adding that flag causes the linker to load all the object files in the Facebook SDK, including the FBLoginView class. If you want to know more about what the -ObjC flag does, you can check out our troubleshooting guide.
It mentioned the FBLoginView, but according to the answer to this question, it also works for FBProfilePictureView: FBProfilePictureView object wont show image
Hope this helps.

Related

How do I view Obj-C subclass variables from Swift in the Xcode debugger?

I've got a mixed Obj-C / Swift project. Whenever I hit a breakpoint in a Swift class, the Obj-C object variables view just shows values for parent classes, but not the subclass itself.
For instance, if I have the following Obj-C class:
#interface CameraPlayerCell
#property (nonatomic, strong) Camera* camera;
#end
When I hit a breakpoint in my Swift CollectionViewController implementation, the Xcode debugger values view shows:
Searched for this for about an hour, but apparently I don't know how to ask Google what I'm looking for (or they're just being Google & showing me what they think I want rather than what I actually want...)
I know there is a way to add an expression to the Variables View so that it will show the member variables for CameraPlayerCell. I've read an article somewhere and have done this before, but for the life of me I cannot remember how to do it.
Have you tried frame variable?
From Apple:
"You use the frame variable (f v) command to get a list of all the variables in the stack frame."
Example:
Cast the value:
po (CameraPlayerCell *)cell
Then you can access the subclass properties:
po ((CameraPlayerCell *) cell).camera
Works fine on my machine. Keep in mind that an Objective-C property is merely a shorthand for accessor methods for an ivar; it is the ivar that will appear in the variables list. (I assume that yours is automatically synthesized.)

IB_DESIGNABLE build failed when using class from within a framework

I created a new embedded framework. Within the framework I created a class called "WBButton", which is a subclass of UIButton. I have set the IB_DESIGNABLE and added IBInspectable attributes to allow configuration through Interface builder, as explained here.
It works fine when I test it from within my framework (by adding a sample .xib and placing the button on the screen), but when adding the custom button to a nib located on the project which contains the framework, I get a "Build Failed" message next to the "Designables" (see below).
Also, what does "Module" mean in Interface builder?
Xcode 6 has a bug that breaks IB_DESIGNABLE classes defined in static library or framework. The same is with CocoaPods which use static library for all Pods.
It seems this is an Xcode bug
Temporary workaround:
Create an empty category/extension in the target that contains the storyboard or nib you want to use the designable view in.
Swift:
extension CustomView {
}
Objective-C:
//.h
#interface CustomView (Category)
#end
//.m
#implementation CustomView (Category)
#end
#Andy's comment above is correct answer if you use CocoaPods and your custom library is not working, you need to uncomment use_frameworks! in your Podfile and "pod install" again.
Apparently the "IB_DESIGNABLE" is not recognized by XCode if you don't do this.

Using CorePlot with OSX for OSX App

Some background: I'm making a Obj-C project for some numerical analysis, and want to add a graph. I found core-plot, and had no problem adding the framework and QuartzCore frameworks to my project.
My question now is how to actually utilise it - I have a project with an interface through Interface Builder (MainMenu.xib), an AppDelegate and another class used for modelling the mathematics. I have searched the internet and can only find tutorials for its use within iOS, which isn't what I'm doing - and I don't understand how to convert that to OSX.
I had assumed that I would add a custom view to the MainMenu.xib and link that to a new property using someting along the lines of
#property (assign) IBOutlet NSView *graph;
Although now that I look at it, putting a NSView object inside a NSObject interface seems silly.
Thanks in advance for your help!
Update 1: So I changed my code to
#property (assign) IBOutlet CPTGraphHostingView *graph;
And changed the property of the custom view to the same, CPTGraphHostingView. The two are now linked, and I have an outlet called "graph" to play with. The challenge is now putting a graph into that space.
Thanks again!

NSCFString or UIViewController?

I am using UIViewController (a subclass of course) with a text field which sends an action when the contents changed (to the contentsChanged: selector of the ViewController). It is done by sending contentsChanged: to file's owner in IB.
But when I test it, it says : "-[NSCFString contentsChanged:] : unrecognised selector sent to instance " and the instance pointer in hex.
I am guessing that for some reason the view controller gets moved to another pointer and a string gets allocated there, but I cannot figure why.
Any ideas ?
Sounds like a classic case. Read up on NSZombieEnabled for how to track this sort of problem down.
I have the exact same problem with a subclass of UIViewController and this piece of innocuous code:
- (void)viewDidLoad
{
NSLog(#"%# %s %#", [self class], _cmd, answerButton);
[self.answerButton addTarget:self
action:#selector(getAnswerToQuestion:)
forControlEvents:UIControlEventTouchUpInside];
}
Yes, answerButton is connected (it's an IBOutlet), yes, - (IBAction)getAnswerToQuestion:(id)sender; is a proper method, but no joy. When I commented out the viewDidLoad and made the connection in IB, it showed in the crash report that the failure happens on [UIControl sendAction:to:forEvent:] resulting in
objc_msgSend() selector name: performSelector:withObject:withObject:
I can't prove it, but I suspect there's a bug somewhere in the UIKit that translates the bindings and addTarget to a call to performSelector. I'm planning to upgrade to iOS 4.01 first to see if that won't solve the problem.
UPDATE:
I'm not sure anymore that my problem really is similar to Alexandre Cassagne's but in the interest of sharing information I will not delete it just yet. I solved my problem, as so often, when I started to make an example project in order to file a bug report. Yes, clicking made answerButton call getAnswerToQuestion: like a good little object and all was fine.
The difference between the subclassed UIViewController of the example project and that of my real project was that the first also functioned as the xib's File's Owner while the second was just one of several view controller. When I moved getAnswerToQuestion: to the File's Owner in my real project, clicking answerButton worked as expected. So, my hunch that the problem lay somewhere in the translation from binding to performSelector wasn't that far off: the problem lies in the Responder Chain. I would think that establishing the Action-Target link either programmatically or in IB would bypass the Responder Chain, but apparently not.
The problem now, of course, is that Alexandre states in his question that his contentsChanged: method already is part of the File's Owner, which makes my answer irrelevant to the question.
without looking at the code, it looks like you are calling contentsChanged: on the text field's text, instead of the UIViewController subclass.
you should consider using the UITextFieldDelegate protocol to get called back when the text of a UITextField changes. I have not looked, but this is the thing I would do off the top of my head.

Objective C, Core Data issue

I'm following a tutorial in "More iPhone 3 Development. In the code, they have a line:
NSManagedObjectContext *managedObjectContext = appDelegate.managedObjectContext;
I get an error: "accessing unknown 'managedObjectContext' getter method" on that line.
I've downloaded his sample code and his program runs fine with that line of code. I've tried rewriting the code and I've even copied and pasted his code into my program, but I still get the error.
I am using the newest SDK, and I'm wondering if something might have changed so this getter method doesn't work anymore, but I do not get any warning about deprecation.
Does anyone know what is going on, or better yet, a better way to write this line and not get the error.
Thanks
LadyDev
When you create a core data project there's a method that is automatically created for you...
- (NSManagedObjectContext *) managedObjectContext
That's your AppDelegate's getter method for the managed object context. Also in the header file you will see that getter method defined:
#property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext;
So make sure you AppDelegate has these then you should not have that problem.
I had the same problem, i found that when I created the project it put 3 #property declarations in the SuperDBAppDelegate.m file which may be a new way of doing it i'm not quite sure. Anyway I took it from there and put it in the .h file and that fixed the error, however now I have other issues which I am still debugging but hopefully that works for you.