2011-12-26 44 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

相關問題