Facebook Liking不像iOS那样工作

时间:2014-05-21 10:17:13

标签: ios iphone objective-c facebook

我试图弄清楚为什么我的代码无法正常工作,尽管我的代码基于可正常工作的示例。 这是我班级的代码:

#import "FBClass.h"
#import "FBConnect.h"
#import "FacebookLikeView.h"


@interface FBClass () <FacebookLikeViewDelegate, FBSessionDelegate>
@property (nonatomic, strong) Facebook *facebook;
@property (strong, nonatomic) FacebookLikeView *facebookLikeView;

@end

@implementation FBClass

@synthesize facebookLikeView = facebookLikeView;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        UIColor * color = [UIColor colorWithRed:120/255.0f green:120/255.0f blue:120/255.0f alpha:1.0f];
        self.view.backgroundColor = color;

         self.facebook = [[Facebook alloc] initWithAppId:@"7592374973434" andDelegate:self];

          UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
         myButton.tintColor = [UIColor blackColor];
         [myButton sizeToFit];
         [myButton addTarget:self action:@selector(myCustomFunction:) forControlEvents:UIControlEventTouchUpInside];



        UILabel *lbl1 = [[UILabel alloc] init];
        lbl1.textColor = [UIColor blackColor];
        lbl1.backgroundColor=[UIColor clearColor];
        lbl1.textColor=[UIColor whiteColor];
        lbl1.userInteractionEnabled=NO;
        lbl1.text= @"textoadkow";


        self.facebookLikeView = [[FacebookLikeView alloc] init];
      //  [facebookLikeView setBackgroundColor:[UIColor orangeColor]];

           [lbl1 setFrame:CGRectMake(35, 60, 400, 100)];
            lbl1.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];


            myButton.frame = CGRectMake(85, 40, 150, 50);
            myButton.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:35];
            [myButton setTitle:@"Tap" forState:UIControlStateNormal];
            [facebookLikeView setFrame:CGRectMake(85, 150, 150, 50)];

        [self.view addSubview:lbl1];
        [self.view addSubview:myButton];
     [self.view addSubview:facebookLikeView];


        self.facebookLikeView.href = [NSURL URLWithString:@"https://www.facebook.com/pages/pageName/id"];
        self.facebookLikeView.layout = @"button_count";
        self.facebookLikeView.showFaces = NO;
        self.facebookLikeView.alpha = 0;
        [self.facebookLikeView load];
    }
    return self;
}

#pragma mark FBSessionDelegate

- (void)fbDidLogin {
    self.facebookLikeView.alpha = 1;
    [self.facebookLikeView load];
}

- (void)fbDidLogout {
    self.facebookLikeView.alpha = 1;
    [self.facebookLikeView load];
}

而#34; This&#34;工作正常。我基于&#34; Link&#34;我唯一改变的是我以编程方式创建我的视图。问题是创建的视图中没有任何内容。

问题在哪里?

1 个答案:

答案 0 :(得分:0)

问题在于这一行 -

self.facebookLikeView.alpha = 0;

使控件不可见(将Alpha通道设置为0)。

将其更改为

self.facebookLikeView.alpha = 1.0; 

并且您的控件应该出现。我不知道为什么该行在示例代码中。我只能假设使用xib文件中的控件以某种方式重置alpha。

还缺少演示代码

self.facebookLikeView.delegate=self;

如果没有这个,你的委托方法就不会被解雇