预期表达并添加额外括号

时间:2015-01-07 00:35:26

标签: ios objective-c

好的,我已经连续几天都在研究这个问题了,我似乎无法弄清楚为什么我会继续获得预期的表达以及为什么Xcode要我在代码中添加额外的括号。任何帮助将不胜感激。

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == self.objects.count)
    {
        return nil;
    }
    static NSString *CellIdentifier    = @"SectionHeaderCell";
    UITableViewCell *sectionHeaderView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    UILabel *userName           = (UILabel *)[sectionHeaderView viewWithTag:1];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

    [dateFormat setDateFormat:@"EEE, MMM d, h:mm a"];

    UILabel *dateLabel = (UILabel *)[sectionHeaderView viewWithTag:2];

    PFObject *post = [self.objects objectAtIndex:section];
    PFUser *user   = [post objectForKey:@"username"];
    userName.text  = user.username;

    //follow button
    //problem is here
    LikeButton *LikeButton  = (LikeButton *)[sectionHeaderView viewWithTag:3];
    //^^^^
    LikeButton.delegate     = self;
    LikeButton.sectionIndex = section;



    if (!self.likeArray || [user.objectId isEqualToString:[PFUser currentUser].objectId])
    {
        LikeButton.hidden = YES;
    }
    else
    {
        LikeButton.hidden = NO;
        NSInteger indexOfMatchedObject = [self.likeArray indexOfObject:user.objectId];
        if (indexOfMatchedObject == NSNotFound)
        {
            LikeButton.selected = NO;
        }
        else
        {
            LikeButton.selected = YES;
        }
    }
    return sectionHeaderView;
}

1 个答案:

答案 0 :(得分:0)

我在你的代码中看到了很多问题。

LikeButton *LikeButton = (LikeButton *)[sectionHeaderView viewWithTag:3];

您声明的变量名称与您的类名相同,这就是您收到错误的原因。将其更改为:

LikeButton *likeBtn = (LikeButton *)[sectionHeaderView viewWithTag:3];

为什么要在viewForHeaderInSection:中对单元格进行出列,是否实现了cellForRowAtIndexPath:方法?