我的应用程序包含两个数组(即productArray和priceArray)并传递单元格上的一个数组的值。 textlabel.text和其他数组cell.detaillabel.text.It工作正常。现在我想按照升序价格列表UICEVIEW排序。请指导我如何做到这一点..这是我的代码..按照升序价格排序uitableview
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController {
NSMutableArray *productArray;
NSMutableArray *priceArray;
}
@property(nonatomic,retain)NSMutableArray *productArray;
@property(nonatomic,retain)NSMutableArray *priceArray;
@end
#import "RootViewController.h"
@implementation RootViewController
@synthesize productArray,priceArray;
- (void)viewDidLoad {
[super viewDidLoad];
productArray=[[NSMutableArray alloc]initWithObjects:@"Apple",@"iphone",@"ipod",@"ipad",nil];
priceArray=[[NSMutableArray alloc]initWithObjects:@"4000",@"2000",@"100",@"1000",nil];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [productsArray count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
cell.textLabel.text=[productsArray objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[priceArray objectAtIndex:indexPath.row];
return cell;
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Relinquish ownership any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
// For example: self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
你应该把原始的源代码放在这里,不要包含我的建议中的代码,因为这个问题会让所有看到它的人感到困惑。 – bneely 2012-02-16 12:21:04
@bneely.Updated :) – NoviceDeveloper 2012-02-16 12:34:42