gpt4 book ai didi

iphone - 为什么我的应用程序崩溃了? UITable 和 Controller

转载 作者:太空狗 更新时间:2023-10-30 03:52:25 25 4
gpt4 key购买 nike

我有一张大表,它可以正常工作,即使与我从下载的示例中打开的更复杂的单元格相比,我觉得它太慢了。当我单击一个单元格然后返回时出现问题,在快速滚动的几秒钟内应用程序在该行崩溃:charImage.image = [self imageForIndex:ch.charId];

如果我删除它会在下一行崩溃: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;


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

[ session 开始于 2009-10-05 07:41:25 +0300。]GNU gdb 6.3.50-20050815(Apple 版本 gdb-967)(UTC 2009 年 7 月 14 日星期二 02:11:58)版权所有 2004 Free Software Foundation, Inc.GDB 是免费软件,受 GNU 通用公共(public)许可证保护,您是欢迎在特定条件下更改它和/或分发它的副本。键入“show copying”以查看条件。GDB 绝对没有任何保证。键入“显示保修”以获取详细信息。此 GDB 配置为“i386-apple-darwin”。sharedlibrary apply-load-rules all附加到进程 96464。(gdb) ^C在哪里

#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

假设您的意思是 EXC_BAD_ACCESS...

这是因为从 [charsList objectAtIndex:row+section*26] 返回的“ch”值不是有效对象。

具体原因您需要自己去发现,但最可能的原因是您释放该对象的次数过多。也有可能对象在插入到 NSArray 时不是有效的 Objective-C 对象。

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

--

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

关于iphone - 为什么我的应用程序崩溃了? UITable 和 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1513505/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com