Iphone iOS版Facebook API中的Analyzer警告

Iphone iOS版Facebook API中的Analyzer警告,iphone,objective-c,ios,facebook,analyzer,Iphone,Objective C,Ios,Facebook,Analyzer,以下是APICallsViewController文件中的代码和几个屏幕截图。我的应用程序正在崩溃,我不确定这是否是原因 谢谢你的帮助 // Customize the appearance of table view cells. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UILabel *textLabel;

以下是APICallsViewController文件中的代码和几个屏幕截图。我的应用程序正在崩溃,我不确定这是否是原因

谢谢你的帮助

 // Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UILabel *textLabel;
    UILabel *detailTextLabel;
    UIButton *button;

    UIFont *cellFont = [UIFont boldSystemFontOfSize:14.0];
    UIFont *detailCellFont = [UIFont fontWithName:@"Helvetica" size:12.0];

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        // Initialize API title UILabel
        textLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
        textLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
        textLabel.tag = TITLE_TAG;
        textLabel.font = cellFont;
        [cell.contentView addSubview:textLabel];

        // Initialize API description UILabel
        detailTextLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
        detailTextLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
        detailTextLabel.tag = DESCRIPTION_TAG;
        detailTextLabel.font = detailCellFont;
        detailTextLabel.textColor = [UIColor darkGrayColor];
        detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
        detailTextLabel.numberOfLines = 0;
        [cell.contentView addSubview:detailTextLabel];

        // Initialize API button UIButton
        button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin;
        [button setBackgroundImage:[[UIImage imageNamed:@"MenuButton.png"]
                                    stretchableImageWithLeftCapWidth:9 topCapHeight:9]
                          forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [button addTarget:self action:@selector(apiButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [cell.contentView addSubview:button];
    } else {
        textLabel = (UILabel *)[cell.contentView viewWithTag:TITLE_TAG];
        detailTextLabel = (UILabel *)[cell.contentView viewWithTag:DESCRIPTION_TAG];
        // For the button cannot search by tag since it is not constant
        // and is dynamically used figure out which button is clicked.
        // So instead we loop through subviews of the cell to find the button.
        for (UIView *subview in cell.contentView.subviews) {
            if([subview isKindOfClass:[UIButton class]]) {
                button = (UIButton *)subview;
            }
        }
    }

    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);

    // The API title
    NSString *cellText = [[apiMenuItems objectAtIndex:indexPath.row] objectForKey:@"title"];
    CGSize labelSize = [cellText sizeWithFont:cellFont
                            constrainedToSize:constraintSize
                                lineBreakMode:UILineBreakModeWordWrap];
    textLabel.frame = CGRectMake(20, 2,
                                  (cell.contentView.frame.size.width-40),
                                  labelSize.height);
    textLabel.text = cellText;

    // The API description
    NSString *detailCellText = [[apiMenuItems objectAtIndex:indexPath.row] objectForKey:@"description"];
    CGSize detailLabelSize = [detailCellText sizeWithFont:detailCellFont
                                        constrainedToSize:constraintSize
                                            lineBreakMode:UILineBreakModeWordWrap];
    detailTextLabel.frame = CGRectMake(20, (labelSize.height + 4),
                                       (cell.contentView.frame.size.width-40),
                                       detailLabelSize.height);
    detailTextLabel.text = detailCellText;


    // The API button
    CGFloat yButtonOffset = labelSize.height + detailLabelSize.height + 15;
    button.frame = CGRectMake(20, yButtonOffset, (cell.contentView.frame.size.width-40), 44);
    [button setTitle:[[apiMenuItems objectAtIndex:indexPath.row] objectForKey:@"button"]
            forState:UIControlStateNormal];
    // Set the tag that will later identify the button that is clicked.
    button.tag = indexPath.row;


    return cell;
}


按钮
变量是一个局部变量。除非您使用的是ARC,否则不能保证将其初始化为任何内容。这可能是胡说八道。分析仪警告您,在您尝试向其发送消息时,尚不清楚是否已为其分配了有意义的地址(“代码>帧”属性的设置器就是您正在发送的消息)

考虑一下:
单元格
不是
nil
,并且在其子视图中找不到按钮。如果是这种情况,应用程序将到达有问题的行,而从未分配给
按钮
变量。它可以包含指向任何位置的指针。如果试图取消对指针的引用以向对象发送消息,则可能会在应用程序中的任何位置的内存上涂鸦

现在,您可能知道一定会找到一个子类,即按钮。但分析人员却无法理解这一点。所以不管怎样,它都会警告你


您应该将
按钮
变量初始化为
nil
。如果可能找不到按钮,则应处理该情况。

按钮变量是局部变量。除非您使用的是ARC,否则不能保证将其初始化为任何内容。这可能是胡说八道。分析仪警告您,在您尝试向其发送消息时,尚不清楚是否已为其分配了有意义的地址(“代码>帧”属性的设置器就是您正在发送的消息)

考虑一下:
单元格
不是
nil
,并且在其子视图中找不到按钮。如果是这种情况,应用程序将到达有问题的行,而从未分配给
按钮
变量。它可以包含指向任何位置的指针。如果试图取消对指针的引用以向对象发送消息,则可能会在应用程序中的任何位置的内存上涂鸦

现在,您可能知道一定会找到一个子类,即按钮。但分析人员却无法理解这一点。所以不管怎样,它都会警告你


您应该将
按钮
变量初始化为
nil
。如果可能找不到按钮,则应处理该情况。

else
语句中,
ui按钮*按钮未初始化。看看if语句中的情况:

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
但是在
else中,缺少初始化。你可以在以下内容后加上:

} else {
        textLabel = (UILabel *)[cell.contentView viewWithTag:TITLE_TAG];
        detailTextLabel = (UILabel *)[cell.contentView viewWithTag:DESCRIPTION_TAG];
        button = (UIButton *)[cell.contentView viewWithTag:indexPath.row]; // <---- add this
以前

[cell.contentView addSubview:button];

在if语句的末尾…

else
语句中,
UIButton*按钮
未初始化。看看if语句中的情况:

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
但是在
else中,缺少初始化。你可以在以下内容后加上:

} else {
        textLabel = (UILabel *)[cell.contentView viewWithTag:TITLE_TAG];
        detailTextLabel = (UILabel *)[cell.contentView viewWithTag:DESCRIPTION_TAG];
        button = (UIButton *)[cell.contentView viewWithTag:indexPath.row]; // <---- add this
以前

[cell.contentView addSubview:button];

在if语句的末尾…

太棒了!谢谢你的帮助。它工作得很好,再也不令人讨厌了!谢谢你的帮助。它工作得很好,不再发生碰撞