我得到错误的错误类型参数为一元减号和预期';'在':'标记之前
错误发生在 - (NSIndexPath *).... line
我真的很新,所以如果还有需要的信息,请询问,如果你需要查看整个应用程序,请发送电子邮件给@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];
}
}
答案 0 :(得分:2)
当编译器到达- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
时,它认为它仍然在前一个方法的定义中。这就是为什么它试图将 - 作为一元减去而不是新方法定义的开始。
这意味着你错过了你发布的代码之上的某个地方 - 可能是在之前的方法定义中。
答案 1 :(得分:0)
尝试使用代码折叠查找缺少的花括号: - 右键单击包含 XCODE 错误的代码文件,然后选择 代码折叠 - &gt;折叠方法/功能选项 要么 快捷键: - 按控制+命令+向上箭头键