2011-07-02 50 views
0

我有一個數據庫應用程序,我正在從sqlite數據庫提取結果並將它們放在表中,但是我需要使它們按字母順序排列。分段tableview問題

所以,現在我有這樣的代碼

AArray = [[NSMutableArray alloc] init]; 
    BArray = [[NSMutableArray alloc] init]; 
    CArray = [[NSMutableArray alloc] init]; 
    DArray = [[NSMutableArray alloc] init]; 
    EArray = [[NSMutableArray alloc] init]; 
    FArray = [[NSMutableArray alloc] init]; 
    GArray = [[NSMutableArray alloc] init]; 
    HArray = [[NSMutableArray alloc] init]; 
    IArray = [[NSMutableArray alloc] init]; 
    JArray = [[NSMutableArray alloc] init]; 
    KArray = [[NSMutableArray alloc] init]; 
    LArray = [[NSMutableArray alloc] init]; 
    MArray = [[NSMutableArray alloc] init]; 
    NArray = [[NSMutableArray alloc] init]; 
    OArray = [[NSMutableArray alloc] init]; 
    PArray = [[NSMutableArray alloc] init]; 
    QArray = [[NSMutableArray alloc] init]; 
    RArray = [[NSMutableArray alloc] init]; 
    SArray = [[NSMutableArray alloc] init]; 
    TArray = [[NSMutableArray alloc] init]; 
    UArray = [[NSMutableArray alloc] init]; 
    VArray = [[NSMutableArray alloc] init]; 
    WArray = [[NSMutableArray alloc] init]; 
    XArray = [[NSMutableArray alloc] init]; 
    YArray = [[NSMutableArray alloc] init]; 
    ZArray = [[NSMutableArray alloc] init]; 

和我有代碼,每個項目從數據庫移動到相關的陣列,這一切工作正常。

然後我有這樣的代碼:

All = [NSMutableDictionary dictionaryWithObjectsAndKeys:AArray,@"A",BArray,@"B",CArray,@"C",DArray,@"D",EArray,@"E",FArray,@"F",GArray,@"G",HArray,@"H",IArray,@"I",JArray,@"J",KArray,@"K",LArray,@"L",MArray,@"M",NArray,@"N",OArray,@"O",PArray,@"P",QArray,@"Q",RArray,@"R",SArray,@"S",TArray,@"T",UArray,@"U",VArray,@"V",WArray,@"W",XArray,@"X",YArray,@"Y",ZArray,@"Z",nil]; 
    AllArray = [NSArray alloc]; 
    AllArray = [AllArray initWithArray:[[All allKeys]sortedArrayUsingSelector:@selector(compare:)]]; 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    // Return the number of sections. 
    return [AllArray count]; 
} 


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    NSArray *Array = [All objectForKey:[AllArray objectAtIndex:section]]; 
    return [Array count]; 
} 
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    int sectionindex = section; 
    return [AllArray objectAtIndex:sectionindex]; 

} 

當我運行它工作正常,但是如果我上下滾動幾次應用程序崩潰,沒有任何錯誤信息。 這是值得做的部分,因爲它崩潰的時候我加入他們,但我看不出有什麼即時通訊做在H文件中聲明錯誤

萬物與我@property和@synthesize以下

@property (nonatomic,retain) NSMutableDictionary *All; 
@property (nonatomic,retain) NSArray *AllArray; 
@property (nonatomic, retain) UITableView *TableView; 

如果有人能幫助我,那將非常棒!

謝謝!

回答

1

您的字典「全部」似乎沒有被保留。您似乎將字典對象直接分配給實例變量,而不是屬性(在這種情況下,您將使用self.All)。

如果您的應用程序崩潰而沒有消息,那麼請確保在Xcode的工具欄中啓用斷點按鈕。這將在調試器中運行該應用程序,這將爲您提供有關崩潰的更多有用信息。將NSZombieEnabled設置爲YES也有幫助。

+0

這已經修好了!非常感謝! – ApiMail

+1

只要網站允許,我會盡快接受您的回答。 – ApiMail

0

看看這裏:

最簡單的方法是,提供一種選擇(見鏈接瞭解詳細信息):

sortedArray = [anArray sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];