2011-12-26 45 views
0

当我尝试导入时,它在导入时出现错误,指出“方法定义不在@implementation上下文中”。我认为错误在于以下代码...方法定义不在@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; 

} 

无法想象它。

+0

您是否意外地将这些方法定义放在某个类的头文件中,在它的接口中?这些文件在哪里? – 2011-12-26 07:35:51

+0

didSelectRowAtIndexPath是我抛出此错误的唯一修改。我做了#import ViewAgencyController并添加了底部部分 – savagenoob 2011-12-26 07:38:53

回答

2

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

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

+0

您的权利,我在@end之后头文件中有一些额外的废话......谢谢。 – savagenoob 2011-12-26 07:46:50

相关问题