我对编程任何类型的设备都很陌生,并且处于陡峭的学习曲线上,所以请原谅我,如果这没有太多意义,或者问题中的代码很糟糕 - 我们都可以从某个地方开始,并相信我,我已阅读,阅读和阅读!
我正在从plist创建一个表,这是一个dictionarys数组 - 我需要它以这种格式,因为我希望能够更改一些值并写回相关的plist'键'。 我希望有人能够看到这个,并给我一些关于如何...的一些指示。
显然,我要把这一切都排除在外还有很长的路要走 - 现在代码本身就像是“狗吃晚餐”,因为我一直在尝试这么多不同的东西而没有太大的成功,所以如果你看到的话你不喜欢请告诉我!
我一直在尝试阅读所有相关部分,例如UILocalizedIndexedCollation和sortedArrayUsingDescriptors,但我想我的大脑不仅仅是它......
任何和所有的建议(除非“放弃你,因为我永远不会放弃任何我开始的事情!”)非常感谢!
(开头合成了很多未使用的变量 - 为了简化我在这里发布的内容,我已经采用相关的代码,代码编译没有任何问题,并且工作给了我以下结果: 一个表格,右边有27个字母,其中只有AJ工作(与表格中产生的部分数量相关 - 只有AJ部分。单元格的内容正是我想要的。)
#import "RootViewController.h"
#import "View2Controller.h"
#import "tableviewsAppDelegate.h"
#import "SecondViewController.h"
#import "HardwareRootViewController.h"
#import "HardwareSecondViewController.h"
#import "SoftwareRootViewController.h"
@implementation SoftwareRootViewController
@synthesize dataList2;
@synthesize names;
@synthesize keys;
@synthesize tempImageType;
@synthesize tempImageName;
@synthesize finalImageName;
@synthesize tempSubtitle;
@synthesize finalSubtitleName;
@synthesize tempSubtitleType;
@synthesize finalSubtitleText;
@synthesize sortedArray;
@synthesize cellName;
@synthesize rowName;
//Creates grouped tableview//
- (id)initWithStyle:(UITableViewStyle)style {
if (self = [super initWithStyle:UITableViewStyleGrouped]) {
}
return self;
}
- (void)viewDidLoad {
//loads in backgroundimage and creates page title//
NSString *backgroundPath = [[NSBundle mainBundle] pathForResource:@"background1" ofType:@"png"];
UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundPath];
UIColor *backgroundColor = [[UIColor alloc] initWithPatternImage:backgroundImage];
self.tableView.backgroundColor = backgroundColor;
[backgroundColor release];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:.5 green:.4 blue:.3 alpha:5];
self.title = @"Software";
[super viewDidLoad];
//Defines path for DATA For ARRAY//
NSString *path = [[NSBundle mainBundle] pathForResource:@"DataDetail3" ofType:@"plist"];
//initialises the contents of the ARRAY with the PLIST//
NSMutableArray* nameArray = [[NSMutableArray alloc]
initWithContentsOfFile:path];
//Sorts the items in the list alphabetically//
NSSortDescriptor *nameSorter = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES selector:@selector(caseInsensitiveCompare:)];
[nameArray sortUsingDescriptors:[NSArray arrayWithObject:nameSorter]];
[nameSorter release];
self.dataList2 = nameArray;
[nameArray release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release anything that can be recreated in viewDidLoad or on demand.
// e.g. self.myOutlet = nil;
}
#pragma mark Table view methods
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
SectionsTableIdentifier ];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier: SectionsTableIdentifier ] autorelease];
}
// Configure the cell.
cell.indentationLevel = 1;
cell.textLabel.text = [[self.dataList2 objectAtIndex:indexPath.row]
objectForKey:@"name"];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
//Detremines the cell color according to the value in 'owned' in the plist//
NSString *textColor = [[self.dataList2 objectAtIndex:indexPath.row]
objectForKey:@"owned"];
if ([textColor isEqualToString: @"greenColor"]) {
[cell setBackgroundColor:[UIColor colorWithRed:0.1 green:0.7 blue:0.1 alpha:1]];
}
if ([textColor isEqualToString: @"blackColor"]) {
[cell setBackgroundColor:[UIColor whiteColor]];
}
return cell;
}
// Code For Loading of The View2Controller//
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [[self.dataList2 objectAtIndex:indexPath.row]
objectForKey:@"name"];
NSString *rowTitle = CellIdentifier;
NSLog(@"rowTitle = %@", rowTitle);
[tableView deselectRowAtIndexPath:indexPath animated:YES];
SecondViewController *second = [[SecondViewController alloc] init];
[second setCategory: rowTitle];
[self.navigationController pushViewController:second animated:YES];
[second release];
}
- (void)dealloc {
[dataList2 release];
[super dealloc];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [dataList2 count];
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [dataList2 count]; ///Tells the table that it only needs the amount of cells listed in the DATALIST1 ARRAY//
}//
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)help
{
return [[[UILocalizedIndexedCollation currentCollation] sectionTitles] objectAtIndex:help];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
return [[UILocalizedIndexedCollation currentCollation] sectionForSectionIndexTitleAtIndex:index];
}
@end
任何建议都会非常感激 - 目前我已经在这个工作了大约一个星期而没有成功,我接近放弃,我真的不想这样做!
如果最糟糕的情况发生在最糟糕的情况下,我无法完成这项工作,那么我会愿意为我编写功能,当然只需支付少量费用!
干杯,希望... ...
Chubs
答案 0 :(得分:1)
使用UILocalizedIndexCollation =]