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

kin*_*ran 0 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];
}
Run Code Online (Sandbox Code Playgroud)

我试过右键单击框架 - >添加现有框架,这似乎没有帮助.我想似乎编译器仍然没有看到框架?

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

mar*_*rcc 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;
...
}