有没有办法让 Facebook 按钮在 UITableView 中正确显示?

问题描述 投票:0回答:3

我正在尝试在我的 iPhone 应用程序中使用 Facebook Connect 功能。 我想知道如何在我的

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;

我尝试过使用accessoryView,但结果是这样的:

此外,仅当我点击单元格时,该按钮才会出现。

如果可以的话请帮忙!

ios facebook sdk
3个回答
1
投票

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


0
投票

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

如果您将该按钮添加为单元格视图的子视图,您可以对单元格的布局产生很大的影响,并将 FB 按钮放置在您想要的任何位置。您绝对应该查看这个示例项目,它演示了如何完成大量自定义单元格类型。


0
投票

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

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 按钮的大小。)

放置按钮的两个关键点是设置框架和将按钮添加到accessoryView。 (将其添加到 contentView 也可以工作,尽管您可能需要手动添加标题。)

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

© www.soinside.com 2019 - 2024. All rights reserved.