我有一個數據庫應用程序,我正在從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;
如果有人能幫助我,那將非常棒!
謝謝!
這已經修好了!非常感謝! – ApiMail
只要網站允許,我會盡快接受您的回答。 – ApiMail