为什么我的应用程序崩溃? UITable和控制器 [英] why my app is crashing? UITable and controllers

查看:86
本文介绍了为什么我的应用程序崩溃? UITable和控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个大表,工作没有错误,即使我似乎太慢相比,我从下载的例子打开更复杂的单元格。问题出现时,我单击一个单元格,然后回来,几秒钟滚动快速应用程序崩溃的行: charImage.image = [self imageForIndex:ch.charId];

I have this large table which works without errors, even if seems to me too slow compared to more complex cells i've opened from downloaded examples. The problem comes when i click a cell, then came back, in few seconds of scrolling fast the app is crashing at the line: charImage.image = [self imageForIndex:ch.charId];

如果我删除它在下一行崩溃: titleLabel.text = ch.title;

If i delete it is crashing at the next line: titleLabel.text = ch.title;

有人熟悉吗?感谢。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//NSLog(@"add a new cell at index path %@", indexPath);
// Each subview in the cell will be identified by a unique tag.
static NSUInteger const kTitleLabelTag = 2;
static NSUInteger const kCharImageTag = 3;
static NSString *kCellID = @"CellID";

// Configure the cell


// Declare references to the subviews which will display the char data.
UILabel *titleLabel = nil;
UIImageView *charImage = nil;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellID];

if (cell == nil) {
    // No reusable cell was available, so we create a new cell and configure its subviews.
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID] autorelease];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    [cell setBackgroundColor:[UIColor clearColor]];
    //
    charImage = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"glyphs/a/1.png"]] autorelease];
    charImage.tag = kCharImageTag;
    charImage.autoresizingMask = UIViewAutoresizingNone;
    [cell.contentView addSubview:charImage];

    titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(60, 10, 215, 20)] autorelease];
    titleLabel.tag = kTitleLabelTag;
    titleLabel.font = [UIFont systemFontOfSize:16];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.adjustsFontSizeToFitWidth = YES;
    [cell.contentView addSubview:titleLabel];

} else {
    // A reusable cell was available, so we just need to get a reference to the subviews using their tags.
    charImage = (UIImageView *)[cell.contentView viewWithTag:kCharImageTag];
    titleLabel = (UILabel *)[cell.contentView viewWithTag:kTitleLabelTag];
}


// Get the specific info for this row.
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
Char *ch = (Char *)[charsList objectAtIndex:row+section*26];

// Set the relevant data for each subview in the cell.
// Set the image in the cell
charImage.image = [self imageForIndex:ch.charId];
[charImage sizeToFit];

int centerX = 30;
int centerY = 23;
CGSize size = charImage.frame.size;
charImage.frame = CGRectMake((int)(centerX - size.width / 2),
                             (int)(centerY - size.height / 2),
                             size.width, size.height);

titleLabel.text = ch.title;

return cell;

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

InstantInsightAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSUInteger section = [indexPath section];
NSUInteger row = [indexPath row];
Char *ch = (Char *)[charsList objectAtIndex:row+26*section];

SqlQueries *db = [SqlQueries alloc];
NSArray *glyphsList = [db readGlyphsFromDatabaseAtId: ch.charId];
NSArray *charDescription = [db readMoreInfoFromDatabaseAtId: ch.charId];
Char *charDetails = [db readInstructionsAndQuotesFromDatabaseAtId: ch.charId];
[db release];
[ch release];

// Navigation logic -- create and push a new view controller
self.glyphsView = [[GlyphsViewController alloc] initWithStyle:UITableViewStyleGrouped];

self.glyphsView.glyphsList = glyphsList;
self.glyphsView.charDetails = charDetails;
self.glyphsView.charDescription = charDescription;
[delegate.navController pushViewController:self.glyphsView animated:YES];
[self.glyphsView release];
self.glyphsView = nil;

}

这里是一个详细的错误:它没有说什么,但我确定我看到了一个异常

Here is a detailed error: it doesn't say anything but i'm sure i've saw something with an exception

[Session started at ]
GNU gdb 6.3.50-20050815(Apple version gdb-967)(Tue Jul 14 02:11:58 UTC 2009)
版权所有2004免费软件基金会,
GDB是免费软件,涵盖在GNU通用公共许可证,你是
欢迎更改和/或在某些条件下分发它的副本。
键入显示复制以查看条件。
GDB绝对没有保修。有关详细信息,请键入显示保修。
此GDB配置为i386-apple-darwin.sharedlibrary apply-load-rules all
附加到进程96464.
(gdb)^ C
其中

[Session started at 2009-10-05 07:41:25 +0300.] GNU gdb 6.3.50-20050815 (Apple version gdb-967) (Tue Jul 14 02:11:58 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 96464. (gdb) ^C where

#0  0x95fd5688 in objc_msgSend ()
#1  0x00002f60 in -[IndexViewController tableView:cellForRowAtIndexPath:] (self=0xd19610, _cmd=0x319a6b9c, tableView=0x101be00, indexPath=0xd2e890) at /Users/Cristi/Documents/xcode - iPhone/Instant Insight/InstantInsight/Classes/IndexViewController.m:115
#2  0x30944bd0 in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:withIndexPath:] ()
#3  0x3093e1fc in -[UITableView(UITableViewInternal) _createPreparedCellForGlobalRow:] ()
#4  0x309501f1 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow] ()
#5  0x30947715 in -[UITableView layoutSubviews] ()
#6  0x00b3dd94 in -[CALayer layoutSublayers] ()
#7  0x00b3db55 in CALayerLayoutIfNeeded ()
#8  0x00b3d3ae in CA::Context::commit_transaction ()
#9  0x00b3d022 in CA::Transaction::commit ()
#10 0x00b452e0 in CA::Transaction::observer_callback ()
#11 0x30245c32 in __CFRunLoopDoObservers ()
#12 0x3024503f in CFRunLoopRunSpecific ()
#13 0x30244628 in CFRunLoopRunInMode ()
#14 0x32044c31 in GSEventRunModal ()
#15 0x32044cf6 in GSEventRun ()
#16 0x309021ee in UIApplicationMain ()
#17 0x00002718 in main (argc=1, argv=0xbfffee50) at /Users/Cristi/Documents/xcode - iPhone/Instant Insight/InstantInsight/main.m:14


推荐答案

什么样的崩溃? EXC_BAD_ACCESS (取消引用不指向有效位置的指针)?还是 objc_exception_throw 是某种类型?

What kind of "crashing"? An EXC_BAD_ACCESS (dereferencing a pointer that doesn't point to a valid location)? Or an objc_exception_throw of some kind?

假设您的意思是 EXC_BAD_ACCESS ...

Assuming you mean an EXC_BAD_ACCESS...

这是因为从 [charsList objectAtIndex:row + section * 26] code>不是有效的对象。

This would be because the "ch" value returned from [charsList objectAtIndex:row+section*26] is not a valid object.

确切的原因,你需要发现自己,但最可能的原因是,你已经释放对象一太多次。

The exact reason for this you'll need to discover yourself but the most likely cause is that you've released the object one too many times. There is also the possibility that the object was not a valid Objective-C object when it was inserted into the NSArray.

有时,它有助于设置NSZombieEnabled(command-option- x,转到Arguments选项卡,并将name = NSZombieEnabled和value = 1添加到环境变量中),因为如果您尝试使用释放对象,将立即抛出异常。

Sometimes it helps to set NSZombieEnabled (command-option-x, go to the Arguments tab and add name=NSZombieEnabled and value=1 to the environment variables) since this will throw an exception immediately if you try to use a deallocated object.

-

不相关的风格点:您正在分配SqlQueries,但不是初始化它。如果你 alloc ,总是,总是 init 。即 [[SqlQueries alloc] init] 。如果你不在乎 init ,因为你没有任何实例变量,那么你不应该有 alloc 反正,你的方法应该是类方法。

Unrelated stylistic point: you're allocating SqlQueries but not initializing it. If you alloc, always, always init. i.e. [[SqlQueries alloc] init]. If you don't care about init because you don't have any instance variables, then you shouldn't have an alloc anyway, your methods should be class methods instead.

这篇关于为什么我的应用程序崩溃? UITable和控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆