0

我收到错误错误类型参数一元减号和预期';' 在 ':' 标记之前

错误发生在 - (NSIndexPath *).... 行

我对此真的很陌生,所以如果需要更多信息,请询问,如果您需要查看整个应用程序,请给我发电子邮件 @james at Sevenotwo dot com。该应用程序并不复杂。它基于 Apple 网站上的 iphonedatacorerecipes 代码示例代码。

#pragma mark -
#pragma mark Editing rows

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 NSIndexPath *rowToSelect = indexPath;
    NSInteger section = indexPath.section;
    BOOL isEditing = self.editing;

    // If editing, don't allow notes to be selected
    // Not editing: Only allow notes to be selected
    if ((isEditing && section == NOTES_SECTION) || (!isEditing && section != NOTES_SECTION)) {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
        rowToSelect = nil;    
    }

 return rowToSelect;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSInteger section = indexPath.section;
    UIViewController *nextViewController = nil;

    /*
     What to do on selection depends on what section the row is in.
     For Type, Notes, and Instruments, create and push a new view controller of the type appropriate for the next screen.
     */
    switch (section) {
        case TYPE_SECTION:
            nextViewController = [[TypeSelectionViewController alloc] initWithStyle:UITableViewStyleGrouped];
            ((TypeSelectionViewController *)nextViewController).doctor = doctor;
            break;

        case NOTES_SECTION:
            nextViewController = [[NotesViewController alloc] initWithNibName:@"NotesView" bundle:nil];
            ((NotesViewController *)nextViewController).doctor = doctor;
            break;

        case INSTRUMENTS_SECTION:
            nextViewController = [[InstrumentDetailViewController alloc] initWithStyle:UITableViewStyleGrouped];
            ((InstrumentDetailViewController *)nextViewController).doctor = doctor;

            if (indexPath.row < [doctor.instruments count]) {
                Instrument *instrument = [instruments objectAtIndex:indexPath.row];
                ((InstrumentDetailViewController *)nextViewController).instrument = instrument;
            }
            break;

        default:
            break;
    }

    // If we got a new view controller, push it .
    if (nextViewController) {
        [self.navigationController pushViewController:nextViewController animated:YES];
        [nextViewController release];
    }
}


- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewCellEditingStyle style = UITableViewCellEditingStyleNone;
    // Only allow editing in the instruments section.
    // In the instruments section, the last row (row number equal to the count of instruments) is added automatically (see tableView:cellForRowAtIndexPath:) to provide an insertion cell, so configure that cell for insertion; the other cells are configured for deletion.
    if (indexPath.section == INSTRUMENTS_SECTION) {
        // If this is the last item, it's the insertion row.
        if (indexPath.row == [doctor.instruments count]) {
            style = UITableViewCellEditingStyleInsert;
        }
        else {
            style = UITableViewCellEditingStyleDelete;
        }
    }

    return style;
}


- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    // Only allow deletion, and only in the instruments section
    if ((editingStyle == UITableViewCellEditingStyleDelete) && (indexPath.section == INSTRUMENTS_SECTION)) {
        // Remove the corresponding instrument object from the doctor's instrument list and delete the appropriate table view cell.
        Instrument *instrument = [instruments objectAtIndex:indexPath.row];
        [doctor removeInstrumentsObject:instrument];
        [instruments removeObject:instrument];

        NSManagedObjectContext *context = instrument.managedObjectContext;
        [context deleteObject:instrument];

        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
    }
}
4

2 回答 2

2

当编译器到达时- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath,它认为它仍然在先前方法的定义中。这就是为什么它试图将 - 作为一元减号而不是新方法定义的开始。

这意味着您在发布的代码上方的某处缺少 } —— 可能在之前的方法定义中。

于 2010-04-15T05:12:30.753 回答
0

尝试代码折叠以查找丢失的花括号:- 在包含XCODE错误的代码文件中单击鼠标右键错误的代码文件,然后选择 代码折叠->折叠方法/功能选项或快捷键:-按Control + Command + 向上箭头键

于 2012-03-10T10:06:59.893 回答