gpt4 book ai didi

iphone - 单击按钮时根据字母或数字顺序对 UITableView 进行排序

转载 作者:行者123 更新时间:2023-11-29 04:48:20 26 4
gpt4 key购买 nike

我定制了带有四个标签的 uitableview 单元格以及四个保存每个标签数据的数组。标签1包含对象名称,标签2包含价格,标签3和标签4包含其他数据。现在有两个按钮,在第一个按钮上单击我想按对象名称的字母顺序对表进行排序,在第二个按钮上单击我想根据价格排序..请指导我如何做..这是我的代码。 .

  - (void)viewDidLoad {
[super viewDidLoad];

details=[[NSMutableArray alloc]initWithObjects:@"dress",@"dress",@"dress",@"dress",@"dress",@"",
@"dress",@"",@"dress",nil];
newPrice=[[NSMutableArray alloc]initWithObjects:@"500",@"1000",@"5000",@"2100",@"1222",@"100",@"5223",@"465",@"3216",nil];
oldPrice=[[NSMutableArray alloc]initWithObjects:@"200",@"900",@"6000",@"2220",@"1000",@"",@"5000",@"",@"",nil];


dataList=[[NSMutableArray alloc]initWithObjects:@"Praline rose dress",@"Praline rose dress",@"Multi Colored dress",@"Multi Colored dress",@"Multi Colored dress",@"Praline rose dress",
@"Multi Colored dress",@"Multi Colored dress",@"Praline rose dress",nil];

searchData=[[NSMutableArray alloc]init];
[searchData addObjectsFromArray:dataList];

dataTable.delegate=self;
dataTable.dataSource=self;
[dataTable reloadData];

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier=@"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

if (cell == nil) { cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier: CellIdentifier] autorelease];

UILabel *labelOne = [[UILabel alloc]initWithFrame:CGRectMake(70, 10, 140, 20)];
labelOne.tag = 100;
labelOne.backgroundColor=[UIColor clearColor];
labelOne.font=[UIFont systemFontOfSize:14];
[cell.contentView addSubview:labelOne];
[labelOne release];


labelTwo = [[UILabel alloc]initWithFrame:CGRectMake(260, 10, 140, 20)];
labelTwo.tag = 101;
labelTwo.backgroundColor=[UIColor clearColor];
labelTwo.font=[UIFont systemFontOfSize:14];
labelTwo.textColor=[UIColor colorWithRed:0.25098 green:0.447059 blue:0.07451 alpha:1];
[cell.contentView addSubview:labelTwo];
[labelTwo release];


UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(70, 30, 140, 20)];
label3.tag = 102;
label3.backgroundColor=[UIColor clearColor];
label3.font=[UIFont systemFontOfSize:12];
[cell.contentView addSubview:label3];
[label3 release];


UILabel *label4 = [[UILabel alloc]initWithFrame:CGRectMake(260, 30, 140, 20)];
label4.tag = 103;
label4.backgroundColor=[UIColor clearColor];
label4.font=[UIFont systemFontOfSize:12];
[cell.contentView addSubview:label4];
[label4 release];
}

UILabel *labelOne = (UILabel *) [cell.contentView viewWithTag:100];
labelOne.text = [searchData objectAtIndex:indexPath.row];

labelTwo = (UILabel *) [cell.contentView viewWithTag:101];
labelTwo.text = [[NSString alloc]initWithFormat:@"%@",[newPrice objectAtIndex:indexPath.row]];

UILabel *label3 = (UILabel *) [cell.contentView viewWithTag:102];
label3.text=[[NSString alloc]initWithFormat:@"%@",[details objectAtIndex:indexPath.row]];

UILabel *label4 = (UILabel *) [cell.contentView viewWithTag:103];
label4.text=[[NSString alloc]initWithFormat:@"%@",[oldPrice objectAtIndex:indexPath.row]];



return cell;

最佳答案

if(btn.tag == 500)
{
aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"OrderDate" ascending:YES];
}
if(btn.tag == 501)
{
aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"CustomerGuid" ascending:YES];
}
if (searching) {
[temp_details sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
}
else{
[orders sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
}
[self.tableView reloadData];

给两个按钮设置标签,就可以按照上面的方法排序这些键是来自字典,设置为 TableView 中的标签,我正在使用按下的按钮对这些标签进行排序

关于iphone - 单击按钮时根据字母或数字顺序对 UITableView 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9288530/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com