我收到错误 Wrong type argument to unary minus 和 Expected ';'在':'之前代币
我收到错误一元减号的类型参数错误和预期的“;”在 ':' 令牌之前
错误发生在 - (NSIndexPath *).... 行
我对此真的很新,所以如果需要更多信息,请询问,如果您需要查看整个应用程序,请发送电子邮件-给我发邮件@james,地址是sevenotwo . 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];
}
}
I am getting the error Wrong type argument to unary minus and Expected ';' before ':' token
The error occurs at the - (NSIndexPath *).... line
I am really New at this, so if there is anymore info needed, please ask, if you need to see the entire app, please e-mail me @ james at sevenotwo dot com. the app isn't really complicated. it is based on the sample code on Apple's website for the iphonedatacorerecipes code.
#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];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当编译器到达
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
时,它认为它仍在先前方法的定义内。这就是为什么它试图将 - 视为一元减号而不是新方法定义的开始。这意味着您在发布的代码上方的某处缺少 } - 可能在前面的方法定义中。
When the compiler gets to
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
, it thinks it's still inside the definition of a previous method. That's why it's trying to treat - as a unary minus rather than the start of a new method definition.This means you're missing a } somewhere above the code you posted -- probably in the previous method definition.
尝试代码折叠来查找丢失的花括号:-
右键单击 XCODE 中包含错误的代码文件,然后选择
代码折叠->折叠方法/函数选项
或者
快捷键:-按 Control + Command + 向上箭头键
Try Code Folding to find missing curly braces:-
Right Click in your code file containing error in XCODE And then choose
Code Folding->Fold Methods/Functions options
Or
Short Cut Key:-Press Control + Command + Up Arrow Key