Je reçois une erreur de compilation bizarre - Je ne sais pas s'il y a un "fantôme dans la machine" ou quoi?Weird Switch erreur de cas (iPhone sdk) UITableView
ci-dessous si l'extrait de code où je reçois cette erreur
- (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;
}
J'obtiens l'erreur suivante
/Users/dk/Desktop/xxx/Classes/DetailedLeaveRequestViewController.m:103:0
/Users/dk/Desktop/xxx/Classes/DetailedLeaveRequestViewController.m:103: error: expected expression before 'UITextView'
à la ligne
UITextView *commentsView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
dans le cas 4:
Je double-chec ked la syntaxe et tout à plusieurs reprises, mais n'a pas pu trouver de problèmes. La partie étrange est quand j'ai essayé de compiler la ligne en dessous de la dernière ligne de cas 3: (juste au-dessus de la pause;) il compilé et couru correctement. Ne pouvons-nous pas déclarer et initialiser un objet dans une instruction case? Ai-je manqué quelque chose d'assez basique ici?
Merci.
Je pense que cela est dupe de: http://stackoverflow.com/ questions/92396/why-cant-variables-be-declare-in-a-switch-statement et http://stackoverflow.com/questions/3757445/switch-case-declaration-with-initialization-declaration-and-then- cession - se référer à ceux-ci car ils ont des explications détaillées. –