2013-03-07 68 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

相關問題