尝试使用CGRect时出现语法错误

时间:2009-06-10 22:20:05

标签: iphone objective-c

我正在尝试将子视图添加到tableview单元格中,当然也使用CGRect作为其中的一部分。但是,我在构建时遇到语法错误:

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    switch (indexPath.section) {
        case 1:
            CGRect <<- SYNTAX ERROR cellFrame = CGRectMake(0, 0, 300, 65);
            cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier: CellIdentifier] autorelease];

            CGRect infoRect = CGRectMake(0, 5, 295, 55);
            UILabel *infoLabel = [[UILabel alloc] initWithFrame:infoRect];
            infoLabel.tag = 1;
            [cell.contentView addSubview:infoLabel];
            [infoLabel release];
            break;
        default:
            break;
    }
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

我试过右键单击Frameworks - &gt;添加现有框架,似乎没有帮助。我想似乎编译器仍然没有看到框架?

编辑:事实上,我刚刚注意到CoreGraphics.framework实际上已经加载到项目中了。所以我现在真的很困惑。

1 个答案:

答案 0 :(得分:7)

cellFrame声明之外声明switch

CGRect cellFrame;
switch (indexPath.section) {
case 1:
cellFrame = CGRectMake(0, 0, 300, 65);
break;
...
}

或在其周围放置括号:

switch (indexPath.section) {
case 1:
{ CGRect cellFrame = CGRectMake(0, 0, 300, 65); }
break;
...
}

相关问题