我有一個自定義UITableViewCell
(實際上我已經爲不同的表格分幾次),偶爾桌子會開始「降級」並慢慢崩潰。這是不可能重現崩潰,並將其與以下調用堆棧崩潰:UITableView與自定義UITableViewCell無法正常顯示
特定應用信息:
訂購遠程未能及時恢復
經過的總CPU時間(秒):0.240(用戶0.040,系統0.200),12%的CPU
經過的應用CPU時間(秒):0.000,0%CPU
Thread 0:
0 libSystem.B.dylib 0x310932b8 semaphore_wait_trap + 8
1 libSystem.B.dylib 0x310c0b46 semaphore_wait + 2
2 libSystem.B.dylib 0x3116a7c4 _dispatch_semaphore_wait_slow + 296
3 libSystem.B.dylib 0x31169cb4 _dispatch_barrier_sync_f_slow + 128
4 CoreFoundation 0x3042bb70 __CFMachPortPerform + 92
5 CoreFoundation 0x304236f8 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 20
6 CoreFoundation 0x304236bc __CFRunLoopDoSource1 + 160
7 CoreFoundation 0x30415f76 __CFRunLoopRun + 514
8 CoreFoundation 0x30415c80 CFRunLoopRunSpecific + 224
9 CoreFoundation 0x30415b88 CFRunLoopRunInMode + 52
10 GraphicsServices 0x31eec4a4 GSEventRunModal + 108
11 GraphicsServices 0x31eec550 GSEventRun + 56
12 UIKit 0x313cf322 -[UIApplication _run] + 406
13 UIKit 0x313cce8c UIApplicationMain + 664
14 Order Remote 0x00002a02 0x1000 + 6658
15 Order Remote 0x000029cc 0x1000 + 6604
這裏是個什麼樣子,當它快要崩潰一樣......
http://img819.imageshack.us/i/uitableviewmissingdata2.jpg/
http://img220.imageshack.us/i/uitableviewmissingdata1.jpg/
我已經通過我的所有的內存管理代碼並啓用殭屍和檢查我如何繼承的單元格,我看不到的地方,我錯了。請幫幫我。
...
這裏是一些代碼
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MenuItemCell *cell = (MenuItemCell *)[tableView dequeueReusableCellWithIdentifier:@"MenuItemCell"];
if (cell == nil)
{
cell = [[[MenuItemCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"MenuItemCell"] autorelease];
DLog(@"MenuViewController::cellForRowAtIndexPath: allocating memory for a MenuItemCell");
}
else
{
DLog(@"MenuViewController::cellForRowAtIndexPath: dequeuing an existing MenuItemCell for reuse");
}
cell.accessoryType = UITableViewCellAccessoryNone;
// only display the item modifiers view if the item has one or more modifiers
if([[selectedCategory getModifiers] count] > 0)
{
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
// Configure the cell.
cell.textLabel.text = [[items objectAtIndex:indexPath.row] name];
// build a mutable string from the modifiers and set the text to the result in the detail label
NSMutableString* modifiers = [[NSMutableString alloc] initWithString:@""];
Item* i = [items objectAtIndex:indexPath.row];
for(ItemModifier* modifier_iterator in [i modifiers])
{
[modifiers appendString: [modifier_iterator name]];
[modifiers appendString: @" "];
}
cell.detailTextLabel.text = modifiers;
[modifiers release];
modifiers = nil;
[cell setItem: i];
return cell;
}
@interface MenuItemCell:UITableViewCell的 { 的UILabel * ITEMCOUNT; }
- (void) setItem: (Item*) item;
- (void) resetItemCount;
@end
@implementation MenuItemCell
- (id) initWithStyle: (UITableViewCellStyle) style reuseIdentifier: (NSString*) reuseIdentifier
{
if((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]))
{
itemCount = [[UILabel alloc] initWithFrame:CGRectZero];
[[self contentView] addSubview:itemCount];
}
return self;
}
- (void) resetItemCount
{
[itemCount setText: @""];
[self setNeedsDisplay];
}
- (void) layoutSubviews
{
[super layoutSubviews];
float inset = 10.0;
CGRect bounds = [[self contentView] bounds];
float h = bounds.size.height;
float w = bounds.size.width;
CGRect accessoryViewBounds;
if(!self.accessoryView)
{
accessoryViewBounds = CGRectZero;
}
else
{
accessoryViewBounds = self.accessoryView.bounds;
}
CGRect textLabelBounds = self.textLabel.bounds;
CGRect innerFrame = CGRectMake(round(inset + w/2), textLabelBounds.origin.y, round(w/2 - accessoryViewBounds.size.width - inset * 3), h - 1);
if((innerFrame.size.height >= bounds.size.height) || (innerFrame.size.width >= bounds.size.width))
{
[NSException raise:@"inner frame for MenuItemCell is larger than the contentView bounds" format:@"MenuItemCell (w: %d h: %d) contentView (w: %d h: %d)", innerFrame.size.width, innerFrame.size.height, bounds.size.width, bounds.size.height];
}
// move the rectange to the right side of the cell
itemCount.textAlignment = UITextAlignmentRight;
itemCount.textColor = [UIColor redColor];
itemCount.highlightedTextColor = [UIColor whiteColor];
itemCount.font = [UIFont boldSystemFontOfSize:[UIFont labelFontSize]];
[itemCount setFrame: innerFrame];
}
- (void) setItem: (Item*) item
{
if([item count] > 0)
{
[itemCount setText: [NSString stringWithFormat: @"%d", [item count]]];
}
else
{
[itemCount setText: @""];
}
[self setNeedsDisplay];
DLog(@"MenuItemCell::itemCount %@ %d", [item name], [item count]);
}
- (void) dealloc
{
[itemCount release];
itemCount = nil;
[super dealloc];
}
@end
代碼將在這裏幫助。至少,你的 - [SomeDataSource tableview:cellForRowAtIndexPath:]和你的UITableViewCell的子類。 – 2011-03-20 04:16:56
爲我的一個類添加了cellForRowAtIndexPath和表視圖單元格子類的代碼.. – nick 2011-03-20 09:32:02