【问题标题】:Method Definition Not In @implementation Context: Error方法定义不在@implementation 上下文中:错误
【发布时间】:2011-12-26 07:24:41
【问题描述】:

当我尝试导入时,它会在导入时出现错误,指出“方法定义不在@implementation 上下文中”。我认为错误在于以下代码...

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *infoDictionary = [self.jsonArray objectAtIndex:indexPath.row];
static NSString *Prospects = @"agencyname";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Prospects];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:Prospects] autorelease];
}

// setting the text
cell.text = [infoDictionary objectForKey:@"agencyname"];    
// Set up the cell
return cell;
 }


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath     *)indexPath {
ViewAgencyController *dvController = [[ViewAgencyController alloc] initWithNibName:@"ViewAgency" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil; 

}

想不通。

【问题讨论】:

  • 您是否不小心将这些方法定义放在了某个类的接口中?这些在什么文件中?
  • didSelectRowAtIndexPath 是我修改的唯一引发此错误的内容。我做了#import ViewAgencyController 并添加了底部部分

标签: objective-c cocoa-touch ios4 iphone-sdk-3.0


【解决方案1】:

所有 Objective-C 方法定义必须在 @implemention@end 编译器指令之间。没有这些,编译器就无法知道您希望该方法属于哪个类。

查看您的标头并确保您有一个 @end 指令来关闭您的类声明,并查看您的 .m 文件并确保您之前有一个 @implementation 指令,在您的方法之后有一个 @end实现。

【讨论】:

  • 你说得对,@end 之后我的头文件中有一些额外的废话...谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-06
  • 2018-01-18
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 2020-02-21
相关资源
最近更新 更多