Ios 尝试滚动UITableView时出现异常
我有一个非常简单的应用程序来学习如何在UITableView中使用分区,但有一个例外- 2013-09-17 08:46:19.956节[4497:c07]*-[uuu NSArrayI] objectAtIndex::发送到解除分配实例0x9566d40的消息 整个方法如下-需要帮助Ios 尝试滚动UITableView时出现异常,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个非常简单的应用程序来学习如何在UITableView中使用分区,但有一个例外- 2013-09-17 08:46:19.956节[4497:c07]*-[uuu NSArrayI] objectAtIndex::发送到解除分配实例0x9566d40的消息 整个方法如下-需要帮助 - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.names = dict;
NSArray *array = [[_names allKeys] sortedArrayUsingSelector:@selector(compare:)];
_keys = array;
}
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
NSLog(@"%lu", (unsigned long)[_keys count]);
return [_keys count];
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *key = [_keys objectAtIndex:section];
NSArray *nameSection = [_names objectForKey:key];
return [nameSection count];
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
NSString *key = [_keys objectAtIndex:section];
NSArray *nameSection = [_names objectForKey:key];
static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier];
}
cell.textLabel.text = [nameSection objectAtIndex:row];
return cell;
}
- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *key = [_keys objectAtIndex:section];
return key;
}
您必须保留
\u键
数组,如下所示:
_keys = [[[_names allKeys] sortedArrayUsingSelector:@selector(compare:)] retain];
在这里,您首先获取其他数组中的值,然后将其传递给键 只需直接将值传递给_键,如下所示
_keys = [[_names allKeys] sortedArrayUsingSelector:@selector(compare:)];
同时检查一下self.names,你也在做同样的事情
希望这将对您有所帮助。您试过调试它吗?在哪一行崩溃?在方法-(UITableViewCell*)tableView:(UITableView*)tableView CellForRowatineXpath:(NSIndexPath*)此行上的indexPath NSString*键=[\u keys objectAtIndex:section];它是有效的——但这是本书中的一个例子。但是有ARC版本,我尝试手动管理内存。所以,正如我所看到的,问题就在这里。。谢谢!