Question

J'ai très bien corrigé mes erreurs Xcode Obj-C, mais celle-ci m'a laissé perplexe:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
 if ([[tableList objectAtIndex:indexPath.row] isEqual:@"Standard"]) {
  [StandardSetupViewController *standard = [[StandardSetupViewController alloc] initWithNibName:@"StandardSetupViewController" bundle:nil]]; 

// ERROR OCCURS HERE:
// error: expected ':' before '*' token
// confused by earlier errors, bailing out

  [standard setTitle:@"Standard"];
  [self.navigationController pushViewController:standard animated:YES];
  [standard release];
 }
}

J'ai récupéré le code d'un didacticiel vidéo sur YouTube à l'adresse http: //. www.youtube.com/watch?v=9ozwoETFei0 , puis corrige plusieurs erreurs de codage en le comparant à Début de développement iPhone et à un exemple de code source Apple. J'ai vérifié deux fois pour m'assurer que l'erreur n'était pas dans la page # import. Je publie le code qui apparaît plus tôt dans l'extrait ci-dessus au cas où vous pensez que l'erreur se produit plus haut:

#import "RootViewController.h"

@implementation RootViewController

@synthesize fetchedResultsController, managedObjectContext;

- (void)viewDidLoad {
 self.title = @"Setting Up"; 
 tableList = [[NSMutableArray alloc] init];
 [tableList addObject:@"Standard"];
 [tableList release];
    [super viewDidLoad];

 // Set up the edit and add buttons.
    self.navigationItem.leftBarButtonItem = self.editButtonItem;

    UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)];
    self.navigationItem.rightBarButtonItem = addButton;
    [addButton release];

 NSError *error;
 if (![[self fetchedResultsController] performFetch:&error]) {
  // Handle the error...
 }

}

- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 // Release anything that can be recreated in viewDidLoad or on demand.
 // e.g. self.myOutlet = nil;
}


#pragma mark Table view methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
 return [tableList count]; 
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

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

 // Configure the cell.

 cell.textLabel.text = [[tableList objectAtIndex:indexPath.row] retain];
 [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];

    return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
 if ([[tableList objectAtIndex:indexPath.row] isEqual:@"Standard"]) {
  [StandardSetupViewController *standard = [[StandardSetupViewController alloc] initWithNibName:@"StandardSetupViewController" bundle:nil]]; 

// ERROR OCCURS HERE:
// error: expected ':' before '*' token
// confused by earlier errors, bailing out

  [standard setTitle:@"Standard"];
  [self.navigationController pushViewController:standard animated:YES];
  [standard release];
 }
}

Merci! Steve (qui est "confus" et qui pense à "renflouer" aussi!)

Était-ce utile?

La solution

Vous n’enroulez pas votre StandardSetupViewController entre crochets, c’était le problème.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    if ([[tableList objectAtIndex:indexPath.row] isEqual:@"Standard"]) {
        StandardSetupViewController *standard = [[StandardSetupViewController alloc] initWithNibName:@"StandardSetupViewController" bundle:nil];

        [standard setTitle:@"Standard"];
        [self.navigationController pushViewController:standard animated:YES];
        [standard release];
    }
}

Votre:

[StandardSetupViewController *standard = [[StandardSetupViewController alloc] initWithNibName:@"StandardSetupViewController" bundle:nil]];

Devrait être:

StandardSetupViewController *standard = [[StandardSetupViewController alloc] initWithNibName:@"StandardSetupViewController" bundle:nil];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top