views:

20

answers:

1

Hi,

I am getting a weird compilation error - I dont know if there is a "ghost in the machine" or what?

Below if the code snippet where I am getting this error

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }



 cell.selectionStyle = UITableViewCellSelectionStyleNone;

 if (indexPath.section == 0) {

  switch (indexPath.row) {
   case 0:
    cell.textLabel.text = @"User";
    cell.detailTextLabel.text = @"John Smith";
    break; 
   case 1:
    cell.textLabel.text = @"From";
    cell.detailTextLabel.text = @"12/01/2010";
    break;
   case 2:
    cell.textLabel.text = @"To";
    cell.detailTextLabel.text = @"12/02/2010";
    break;
   case 3:
    cell.textLabel.text = @"Duration";
    cell.detailTextLabel.text = @"30 Days";
    break;
   case 4:
    UITextView *commentsView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
    //commentsView.layer.cornerRadius = 10.0f;
    //[cell.contentView addSubview:commentsView];
    //[commentsView release];
    break;
   default:
    break;
  }
    } else if (indexPath.section == 1) {
  cell.detailTextLabel.text = @"Approve";  
 } else {
  cell.detailTextLabel.text = @"Reject";
 }
    // Configure the cell...

    return cell;
}

I am getting following error

/Users/dk/Desktop/xxx/Classes/DetailedLeaveRequestViewController.m:103:0 
/Users/dk/Desktop/xxx/Classes/DetailedLeaveRequestViewController.m:103: error: expected expression before 'UITextView'

at line

UITextView *commentsView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];

in the case 4:

I double-checked the syntax and everything over and over but could not find any problems. The weird part is when I tried to compile the line below last line of case 3: (just above the break;) it compiled and ran correctly. Can we not declare and initialize an object inside a case statement? Am I missing something fairly basic here?

Thanks.

+1  A: 

You need to add a block limiter to your case statement:

case 4:{
    UITextView *commentsView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
}

or move variable declaration outside of switch statement

Vladimir
Is that for specific reason? All the above cases are getting compiled correctly with multiple statements without block delimiters. Also when I pasted the code below line cell.detailTextLabel.text = @"30 Days"; in case 3: without delimiters, it compiled and ran fine. Please let me know. Thanks.
Dev
@neo, while was looking for a link SedateAlien posted them - you can find good explanation there
Vladimir
@neo: Refer to [this](http://stackoverflow.com/questions/1180550/weird-switch-error-in-obj-c/1181106#1181106) specific answer in another SO thread. It explains in great detail. :-)
Sedate Alien
Awesome ... thanks guys ... saved me a lot of time :)
Dev