【发布时间】:2015-07-08 08:50:27
【问题描述】:
我有一个表格视图控制器,它可以导入一个带有 NSStrings 的 NSObject。在我创建列表的表视图控制器中,不是按字母顺序排列的。 这是我正在使用的代码片段:
歌曲.h:
#import <Foundation/Foundation.h>
@interface Songs : NSObject
@property (nonatomic, retain) NSString* name;
@property (nonatomic, retain) NSString* description;
@property (assign) int serial;
-(id) initWithName:(NSString*) SongName andDescription:(NSString*)theDescription;
@end
songs.m:
#import "Songs.h"
@implementation Songs
@synthesize name;
@synthesize description;
@synthesize serial;
-(id) initWithName:(NSString *)theName andDescription:(NSString *)theDescription
{
self = [super init];
if(self)
{
self.name = theName;
self.description = theDescription;
}
return self;
}
@end
还有表格视图:
#import "TableViewController.h"
#import "DetailViewController.h"
#import "Songs.h"
@implementation TableViewController
@synthesize allTableData;
@synthesize filteredTableData;
@synthesize letters;
@synthesize searchBar;
@synthesize isFiltered;
NSArray *SongsIndexTitles;
SongsIndexTitles = @[@"A", @"B", @"C",@"Ç", @"D", @"E", @"F", @"G", @"H", @"I",@"İ", @"J", @"K", @"L", @"M", @"N", @"O", @"Ö", @"P", @"R", @"S",@"Ş", @"T", @"U",@"Ü", @"V", @"Y", @"Z"];
allTableData = [[NSArray alloc] initWithObjects:
[[Songs alloc] initWithName:@"Ağlarsa Anam Ağlar" andDescription:@"Seslendiren: Abidin"],
[[Songs alloc] initWithName:@"Aynalı Kemer" andDescription:@"Seslendiren: Abidin"],
[[Songs alloc] initWithName:@"Boşuna " andDescription:@"Seslendiren: Abidin"],
[[Songs alloc] initWithName:@"Çöpçüler " andDescription:@"Seslendiren: Abidin"],
[[Songs alloc] initWithName:@"Ahu Gozlum" andDescription:@"Seslendiren: Abidin"],
[[Songs alloc] initWithName:@"Hepsi Senin mi?" andDescription:@"Seslendiren: Abidin"],
[[Songs alloc] initWithName:@"Neredesin Sen?" andDescription:@"Seslendiren: Abidin"],
[[Songs alloc] initWithName:@"Pamuk" andDescription:@"Seslendiren: Abidin"],
[[Songs alloc] initWithName:@"Sen Yoluna Ben Yoluma" andDescription:@"Seslendiren: Abidin "],
[[Songs alloc] initWithName:@"Yolcu Yolunda Gerek" andDescription:@"Seslendiren: Abidin "],
列表还在继续。分段效果很好,但我不知道如何按字母顺序在每个部分中制作歌曲名称;就像在 A 部分一样,它应该是 1-Ahu Gozlum 2-Aglarsa Anam Aglar 3- Aynali Kemer....
任何帮助将不胜感激。
【问题讨论】:
-
在 NSArray 文档中查找名称中带有“sort”的各种方法。
-
然后在 NSString 文档中查找名称中带有“compare”的各种方法。
-
我有,我试过 NSArray *sortedArray = [allTableData sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];但我想我错过了什么
-
你的问题与Xcode无关。
标签: ios objective-c uitableview alphabetical