من الصعب إصلاح خطأ Obj-C:المتوقع ':' قبل الرمز المميز '*' في Xcode

StackOverflow https://stackoverflow.com/questions/1411761

  •  05-07-2019
  •  | 
  •  

سؤال

لقد كنت جيدًا جدًا في إصلاح أخطاء Xcode Obj-C، ولكن هذا الخطأ جعلني في حيرة من أمري:

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

لقد التقطت الكود من فيديو تعليمي على YouTube على http://www.youtube.com/watch?v=9ozwoETFei0, ، ثم أصلح العديد من الأخطاء في الترميز عن طريق التحقق منها بداية تطوير الآيفون وعينة من كود مصدر Apple.لقد قمت بالتحقق مرة أخرى للتأكد من أن الخطأ ليس موجودًا في صفحة #import.أقوم بنشر الترميز الذي حدث مسبقًا في المقتطف أعلاه في حالة اعتقادك أن الخطأ يحدث بشكل أكبر:

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

شكرًا!ستيف (الذي "يشعر بالارتباك" ويفكر في "الإنقاذ" أيضًا!)

هل كانت مفيدة؟

المحلول

أنت لا التفاف الخاص بك StandardSetupViewController مع الأقواس، تلك كانت المشكلة.

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

خاصة بك:

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

يجب ان يكون:

StandardSetupViewController *standard = [[StandardSetupViewController alloc] initWithNibName:@"StandardSetupViewController" bundle:nil];
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top