Привет, друг, я хочу, чтобы имя и фамилия отображались в ячейке, но отображается только имя. Я пытаюсь ответить на какое-то заданное мной эту ссылку
Этот код используется для получения 1-й буквыкаждого штата США (stateName) для группировки их в алфавитном порядке:
personarray = [[NSMutableArray alloc]init];
[personarray addObjectsFromArray:dislist.Peoplelistarray];
//short the personarray value:
NSSortDescriptor *asortDescriptor;
asortDescriptor=[NSSortDescriptor sortDescriptorWithKey:@"FirstName" ascending:YES selector:@selector(caseInsensitiveCompare:)];
//asortDescriptor=[[NSSortDescriptor alloc]initWithKey:@"TagName" ascending:YES];
NSArray *sortDescriptors=[NSArray arrayWithObject:asortDescriptor];
[self.personarray sortUsingDescriptors:sortDescriptors];
//---create the index---
Frstname = [[NSMutableArray alloc] init];
//check
NSMutableArray *tempArray = [[NSMutableArray alloc] init];
for (NSDictionary *row in personarray) {
[tempArray addObject:[row valueForKey:@"FirstName"]];
for (int i=0; i<[tempArray count]; i++){
char alphabet = [[tempArray objectAtIndex:i] characterAtIndex:0];
NSString *uniChar = [NSString stringWithFormat:@"%C", alphabet];
if (![Frstname containsObject:uniChar]){
[Frstname addObject:uniChar];
}
У меня возникают проблемы с пониманием того, как заполнить ячейку табличного представления ОБА @“FirstName"
и @“LastName"
(в качестве подзаголовка)после того как я использую NSPredicate
для сортировки массива
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [Mytableview dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
if (isSearchOn) {
NSString *cellValue = [searchResult objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
}
else {
//---get the letter in the current section---
NSString* alphabet = [Frstname objectAtIndex:[indexPath section]];
//---get all states beginning with the letter---
NSPredicate *predicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSArray *Names = [[personarray valueForKey:@"FirstName"] filteredArrayUsingPredicate:predicate];
if ([Names count]>0) {
//---extract the relevant firstname from the Names object---
NSString *cellValue = [Names objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
}