Я попытался запустить следующий код в качестве подтверждения концепции и получаю следующую ошибку:
*** -[UIAnimator count]: unrecognized selector sent to instance 0x3832610
2009-10-09 00:33:22.355 Concept1[680:207] *** Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: '*** -[UIAnimator count]: unrecognized selector sent to
instance 0x3832610'
Это исключение, по-видимому, относится к переменной, которую я ранее определил как NSArray (то есть переменная 'keys'), поэтому я не понимаю, почему она теперь, похоже, изменилась на UIAnimator. Также досадно, что я не могу найти какую-либо документацию по UIAnimator.
Комментирование освобождения временного массива, используемого для присвоения «ключам» в методе viewDidLoad, приводит к выполнению кода, но я не понимаю, почему ... не произойдет ли сбой при освобождении «массива» утечка, так как этот объект является владельцем этого объекта?
Я был бы чрезвычайно признателен за любую помощь, которую кто-либо мог бы оказать, поскольку сейчас 1 час ночи, и у меня заканчиваются идеи относительно того, что может быть причиной такого поведения.
В любом случае, вот код:
#import "MyViewController.h"
@implementation MyViewController
@synthesize names;
@synthesize keys;
/*
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
if (self = [super initWithStyle:style]) {
}
return self;
}
*/
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"My Details";
NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:@"David", @"First Name", @"Johnson", @"Last Name", nil];
self.names = dic;
[dic release];
NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
self.keys = array;
[array release]; //if this is commented out then the code works. why? won't this leak?
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (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 any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.names = nil;
self.keys = nil;
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [keys count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
cell.textLabel.text = [names objectForKey:[keys objectAtIndex:row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here. Create and push another view controller.
// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
// [self.navigationController pushViewController:anotherViewController];
// [anotherViewController release];
}
- (void)dealloc {
[names release];
[keys release];
[super dealloc];
}
@end