Uitableview 如何在作为子视图添加到uiviewcontroller的tableView中单击按钮对单元格进行排序?

Uitableview 如何在作为子视图添加到uiviewcontroller的tableView中单击按钮对单元格进行排序?,uitableview,nssortdescriptor,Uitableview,Nssortdescriptor,首先,我会提供一些背景信息,这样你们就能完全理解我的问题。我花了好几个小时寻找解决方案,但似乎仍然没有找到正确的方法。因此,我尝试创建一个应用程序,将tableView作为uiviewcontroller(SubviewPracticeMasterViewController)上的子视图加载。该表视图在另一个uiviewcontroller(SubviewPracticeViewController)上是子类化的,并在SubviewPracticeMasterViewController上作为u

首先,我会提供一些背景信息,这样你们就能完全理解我的问题。我花了好几个小时寻找解决方案,但似乎仍然没有找到正确的方法。因此,我尝试创建一个应用程序,将tableView作为uiviewcontroller(SubviewPracticeMasterViewController)上的子视图加载。该表视图在另一个uiviewcontroller(SubviewPracticeViewController)上是子类化的,并在SubviewPracticeMasterViewController上作为uiview加载

我还有一个名为LeadsInformation的NSObject。铅信息。h看起来像这样

#import <Foundation/Foundation.h>

@interface LeadsInformation : NSObject

@property (nonatomic, copy)NSString *leadName;
@property (nonatomic, copy)NSString *lastName;
@property (nonatomic, copy)NSString *firstName;
@property (nonatomic, copy)NSString *areaCode;
@property (nonatomic, copy)NSString *phoneNumber;
@property (nonatomic, copy)NSString *status;
@property (nonatomic, copy)NSString *notes;


-(id)initWithName: (NSString *)leadName lastName: (NSString *)lastName firstName:      (NSString *)firstName
     areaCode: (NSString *)areaCode phoneNumber: (NSString *)phoneNumber status: (NSString *)status 
        notes: (NSString *)notes;

@end
下面是CellForRowatineXpath的代码,以防万一:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:@"Identifier"];
    if (cell == nil) {

        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = [topLevelObjects objectAtIndex:0];
    }

    LeadsInformation *leadAtIndex = [self.dataArray objectAtIndex: indexPath.row];

    UILabel *label;
    label = (UILabel *)[cell viewWithTag:1];
    label.text = leadAtIndex.leadName;

    label = (UILabel *)[cell viewWithTag:2];
    label.text = leadAtIndex.status;

    return cell;
}

任何帮助都将不胜感激。谢谢

所以我原来是在做一些不必要的工作,这让我很扫兴。我不需要对数组的副本进行排序,然后将dataArray作为新的排序副本重新加载。我只需要使用SortDescriptor直接对数组进行排序,如下所示:

-(IBAction)sortLeadName:(id)sender {
    NSSortDescriptor *sortDescript = [[NSSortDescriptor alloc] initWithKey:@"status"  ascending: YES selector:@selector(localizedStandardCompare:)];

    [self.dataArray sortUsingDescriptors: [NSArray arrayWithObject: sortDescript]];
    [self.tableView reloadData];
}
-(IBAction)sortLeadName:(id)sender {
    NSSortDescriptor *sortDescript = [[NSSortDescriptor alloc] initWithKey:@"status"  ascending: YES selector:@selector(localizedStandardCompare:)];

    [self.dataArray sortUsingDescriptors: [NSArray arrayWithObject: sortDescript]];
    [self.tableView reloadData];
}