【问题标题】:Is there a way to make the Facebook button appear correctly in a UITableView?有没有办法让 Facebook 按钮在 UITableView 中正确显示?
【发布时间】:2010-02-25 20:01:38
【问题描述】:

我正在尝试让 Facebook Connect 功能在我的 iPhone 应用程序中运行。 我想知道如何在我的 UITableView 中正确排列按钮:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    if (indexPath.section == 0){
        if (indexPath.row == 0){

        }
    }
    if (indexPath.section == 1){
        if (indexPath.row == 0){
            cell.textLabel.text = @"Connect with Facebook";
            cell.accessoryView = login;

        }
    }

    return cell;

我尝试过使用附件视图,但结果是这样的:

只有当我点击单元格时才会显示该按钮。

如果可以的话请帮忙!

谢谢。

【问题讨论】:

  • 您没有引用实例化并将按钮添加到表中的部分 - 还是在 InterfaceBuilder 中完成?
  • 这是在 viewDidLoad 的代码中完成的: - (void)viewDidLoad { [super viewDidLoad]; login = [[[FBLoginButton alloc] init] autorelease]; }
  • 好的,但我仍然看不到您如何将 FBLoginButton 的实例添加到您的表中。

标签: iphone api facebook sdk


【解决方案1】:

恕我直言,最简单的布局大部分静态 UITableView 的方法是使用 InterfaceBuilder。

【讨论】:

    【解决方案2】:

    accessoryView 肯定会被框在右边,因为“附件”通常是指打开新页面的表格单元格右侧的小扩展箭头小部件等。

    如果您将该按钮添加为单元格视图的子视图,您可以对单元格的布局产生很大影响,并将 FB 按钮放置在您想要的任何位置。您应该非常肯定地查看this sample project,它演示了如何完成一系列自定义单元格类型。

    【讨论】:

      【解决方案3】:

      我刚刚遇到了同样的问题。我的工作代码如下所示:

      FBLoginButton* fbbutton = [[FBLoginButton alloc] initWithFrame:CGRectMake(cellwidth - 30.0 - 10.0,
                                                                                (cellheight - 30.0) / 2.0,
                                                                                90.0, 30.0)];
      fbbutton.style = FBLoginButtonStyleNormal;
      fbbutton.session = session;
      
      cell.accessoryView = fbbutton;
      cell.textLabel.text = @"Facebook";
      [fbbutton release];
      

      (显然我使用了常量而不是硬编码 Facebook 按钮的大小。)

      按钮放置的两个关键位是设置框架并将按钮添加到附件视图。 (将其添加到 contentView 也可以,但您可能需要手动添加标题。)

      至于仅在您按下按钮时出现的按钮,我设法通过显式设置按钮样式来解决该问题。我猜这是 Facebook Connect 库中的错误。

      【讨论】:

        猜你喜欢
        • 2019-08-19
        • 1970-01-01
        • 2012-07-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多