views:

407

answers:

1

I'm trying to add a subview to a tableview cell and of course using CGRect as part of that. However, I get a syntax error on build:

- (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];
}

I have tried right-clicking on Frameworks -> add existing framework and that does not appear to help. I guess it seems like the compiler is still not seeing the framework?

Edit: in fact, I just noticed CoreGraphics.framework was in fact already loaded into the project. So I'm really confused now.

+7  A: 

Declare cellFrame outside of the switch statement:

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

or put brackets around it:


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

marcc
Good grief, you are kidding me.I love Objective-C, I love Objective-C.....
kindaran