预期表达式并添加额外的括号
Expected Expression and adding extra brackets
好吧,我连续几天都在研究这个问题,但我似乎无法弄清楚为什么我一直得到预期的表达式以及为什么 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;
}
我在您的代码中发现了很多问题。
LikeButton *LikeButton = (LikeButton *)[sectionHeaderView viewWithTag:3];
您声明的变量名称与您的 class 名称相同,这就是您收到错误的原因。将其更改为:
LikeButton *likeBtn = (LikeButton *)[sectionHeaderView viewWithTag:3];
为什么要在 viewForHeaderInSection:
中出列单元格?您是否实施了 cellForRowAtIndexPath:
方法?
好吧,我连续几天都在研究这个问题,但我似乎无法弄清楚为什么我一直得到预期的表达式以及为什么 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;
}
我在您的代码中发现了很多问题。
LikeButton *LikeButton = (LikeButton *)[sectionHeaderView viewWithTag:3];
您声明的变量名称与您的 class 名称相同,这就是您收到错误的原因。将其更改为:
LikeButton *likeBtn = (LikeButton *)[sectionHeaderView viewWithTag:3];
为什么要在 viewForHeaderInSection:
中出列单元格?您是否实施了 cellForRowAtIndexPath:
方法?