2013-03-07 126 views
1

我想插入我的自定义对象BalanceDataNSMutableArray,我得到一个错误:插入自定义对象的NSMutableArray

No known class method for selector 'balnce' 

我的代码:

- (void)insertNewObject:(id)sender 
{ 
    if (!_balances) { 
     _balances = [[NSMutableArray alloc] init]; 
    } 
    [_balances insertObject:[BalanceData balance] atIndex:0]; // error occures here 
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0]; 
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; 
} 

MasterViewController.m顶部:

#import "MasterViewController.h" 
#import "DetailViewController.h" 
#import "BalanceData.h" 

@interface MasterViewController() { 
    NSMutableArray *_balances; 
} 
@end 

@implementation MasterViewController 

@synthesize balances = _balances; 

我该如何正确使用它?

+0

“balnce” - 它是错字只是在问题或你的代码呢? – Vladimir 2013-03-07 10:29:46

+0

这不是一个错字。我敢打赌,我不明白这个代码。这是我第一次碰到Objective C. – hsz 2013-03-07 10:31:38

+0

,这意味着你的代码中有拼写错误,你试图调用balnce方法而不是余额 – Vladimir 2013-03-07 10:36:17

回答

1

您班BalanceData没有实施平衡方法。调用这种方式:

[BalanceData balance] 

你调用一个类的方法:

@implementation BalanceData 
+ (id)balance 
{ //implementation} 

在BalanceData写这篇文章和它去细

1

根据您所提供的代码和错误消息,但这似乎没有什么关系的NSMutableArray ...

的运行时间抱怨类BalanceData没有一定的消息作出响应。

所以:你打电话错误的方法?或者你打算调用一个实例方法,而是将其作为一个Class方法调用?或者你是否试图有意地调用Class方法,但没有将它放在你的.h文件中,以便其他外部代码能够看到?

本身试试这一条线:

[BalanceData balance]; 

我敢打赌,运行时不喜欢任何好转,表明您的问题就在这里,不与阵列互动。

+0

类方法声明看起来像'+(sometype)methodname',而实例方法声明使用' - (某种类型) ...'。 – 2013-03-07 10:37:22

相关问题