可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I'm doing the scrumptios facebook developer tutorial for the 3.1 iOS SDK.
I've managed to display my profile name from facebook, however the FBProfilePictureView wont show the picture
here's the code for iboutlet
@property (strong, nonatomic) IBOutlet FBProfilePictureView *useProfileImage;
here is what I used to display the pic
self.useProfileImage.profileID = user.id;
I have confirmed that the it changed the profileid variable of the image by displaying it in a label.
When I first ran the project I had this error
"2012-05-18 04:04:11.620 Scrumptious[6548:f803] Unknown class
FBProfilePictureView in Interface Builder file."
and solved it they way the FB tutorial suggested- by adding [FBProfilePictureView class];
to "applicationdidfinishlaunching: withoptions" in the app delegate.
any idea why the picture wouldn't show?
link to the tutorial
回答1:
Adding the [FBProfilePictureView class];
as the first line in the app delegate method of didFinishLaunching seems kinda hacky to me.
Check out the HelloFacebookSample inside the SDK. Here is the 4 line comment:
// If you have not added the -ObjC linker flag, you may need to uncomment the following line because
// Nib files require the type to have been loaded before they can do the wireup successfully.
// http://stackoverflow.com/questions/1725881/unknown-class-myclass-in-interface-builder-file-error-at-runtime
// [FBProfilePictureView class];
I tried adding the -ObjC
flag and it worked fine.
回答2:
To resolve this, add this as the first line in the app delegate's application:didFinishLaunchingWithOptions: method:
[FBProfilePictureView class];
回答3:
As documented in the facebook webpages you need to put the [FBProfilePictureView class]; as the first line in the app delegate method of didFinishLaunching. (Note their sample code does not have this but still works, in my case it will not work without it.
I created a UIView object sized it up and then selected the class from UIView to FBProfilePictureView. This will disconnect any connection between your program and IB so you need to reconnect again, the error in which you are not able to see the picture is due to the object not being wired up to an IBOutlet item.
I am not sure if a cut and paste will work, maybe it will, but I created the object from UIView and just changed the class manually through IB.
Without the [FBProfilePictureView class]; it will give you an error.
If done correctly, if you view the XIB - in the object window/list you should see "Profile Picture View"along with Button and Label instead of FBProfilePictureView. The profile pic from facebook should show.
回答4:
I have the same problem. My solution is to uncheck the "Use autolayout" option in "File Inspector" of the xib file. To open the "File Inspector", press cmd+option+1 after opening the xib file.
Edit 1: Just find another solution.
Try to set a width constraint and height constraint to the profile picture view. I find this tutorial is useful.
回答5:
I had the same issue, xcode4.5.1 ios6.
to fix do this: in IB uncheck use autolayout for FBprofilepictureview, also uncheck "autoresize subview" into the view
回答6:
They(fb developer forum) said paste that in your app delegate didLunch method like that
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[FBProfilePictureView class];
// Create a LoginUIViewController instance where the login button will be
LoginUIViewController *loginUIViewController = [[LoginUIViewController alloc] init];
// Set loginUIViewController as root view controller
[[self window] setRootViewController:loginUIViewController];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
just replace
[FBProfilePictureView class];
with these commented lines it will work
// Override point for customization after application launch.
// Load the FBProfilePictureView
// You can find more information about why you need to add this line of code in our troubleshooting guide
// https://developers.facebook.com/docs/ios/troubleshooting#objc
[FBProfilePictureView class];
it will work magically :)
回答7:
Classes that use categories to extend existing classes are not loaded automatically. Classes that are used from the Xcode interface builder aren't loaded automatically, for example when you add a FBLoginView to your interface by drawing a view in your .xib file and then classing it as FBLoginView from the interface builder UI.
class
helps to create a pointer to the FBProfilePictureView.