をUITableView
含むカスタム ヘッダーを持つ がありUITextField
ます。そこにテキストを入力し、textfield
[完了] をタップしkeyboard
てキーボードを閉じます。問題なく動作します。
UIActionSheet
テーブル内の行を削除することを確認するために起動される があります。「確認」をタップすると、UIActionSheet
が閉じられ、行が削除されます - 正常に動作します。
しかし、テキストを入力してtextfield
(キーボードを閉じて) 行を削除しようとすると、アプリが一瞬フリーズしてUIActionSheet
からクラッシュします。
これは私が入手したクラッシュレポートです。
Thread 0 Crashed:
0 CoreFoundation 0x00004260 __CFTypeCollectionRetain + 16
1 CoreFoundation 0x00005e38 __CFDictionaryRetainValue + 20
2 CoreFoundation 0x000054a8 __CFBasicHashAddValue + 100
3 CoreFoundation 0x00005158 CFDictionarySetValue + 68
4 UIKit 0x000e3472 -[UITableView(_UITableViewPrivate) _updateWithItems:withOldRowData:oldRowRange:newRowRange:context:] + 1730
5 UIKit 0x000e281e -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] + 4770
6 UIKit 0x0012a4d6 -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 198
7 UIKit 0x0012a3de -[UITableView deleteRowsAtIndexPaths:withRowAnimation:] + 14
8 Tracker8 0x00012502 -[TrackerTableViewController actionSheet:clickedButtonAtIndex:] (PriceTableViewController.m:313)
9 UIKit 0x00369596 -[UIActionSheet(Private) _buttonClicked:] + 186
2 つの要素が個別に機能するのに順番に機能しない理由について何か提案はありますか? ご協力いただきありがとうございます。
更新: 私のコードをさらにテストすると、iOS 4.1 を実行しているデバイスでのみクラッシュが発生することが示されています。iOS 5.1 または iOS 6.0 を実行しているデバイスではクラッシュしません。これにより、おそらく既知の古いバグを扱っていると思います。
ラベルとテキストフィールドを使用してIBで作成されたシミュレートされた「ヘッダービュー」の下にテーブルビューを配置することで、これを回避しました。テキストフィールドが編集されてから行が削除されてもクラッシュしなくなりました。
クラッシュを再現/説明することに興味がある人のために、実装コードを次に示します。
@synthesize table;
@synthesize array;
#pragma mark View Lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableArray *staticArray = [[NSMutableArray alloc] initWithObjects:@"This is the 1st row.",
@"This is the 2nd row.", @"This is the 3rd row.",
@"This is the 4th row.", @"This is the 5th row.",
@"This is the 6th row.", @"This is the 7th row.",
@"This is the 8th row.", @"This is the 9th row.",
@"This is the 10th row.", nil];
self.array = staticArray;
[staticArray release];
}
#pragma mark TableView Data Source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
[cell autorelease];
}
cell.textLabel.text = [self.array objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// remove selected object from the data array
[self.array removeObjectAtIndex:indexPath.row];
// Delete the row from the table.
[self.table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
#pragma mark TableView Delegate
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
// custom header view containing a label and a textfield
UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)]autorelease];
headerView.backgroundColor = [UIColor darkGrayColor];
headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
UILabel *pLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 21)] autorelease];
pLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
pLabel.backgroundColor = [UIColor clearColor];
pLabel.textAlignment = UITextAlignmentCenter;
pLabel.textColor = [UIColor blackColor];
pLabel.font = [UIFont boldSystemFontOfSize:17.0];
pLabel.adjustsFontSizeToFitWidth = YES;
pLabel.minimumFontSize = 10.0;
pLabel.text = @"Table Header";
UITextField *pField = [[[UITextField alloc] initWithFrame:CGRectMake(20, 18, 280, 31)] autorelease];
pField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
pField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
pField.textAlignment = UITextAlignmentCenter;
pField.textColor = [UIColor blackColor];
pField.font = [UIFont systemFontOfSize:17];
pField.adjustsFontSizeToFitWidth = YES;
pField.minimumFontSize = 10.0;
pField.borderStyle = UITextBorderStyleNone;
pField.clearButtonMode = UITextFieldViewModeWhileEditing;
pField.autocapitalizationType = UITextAutocapitalizationTypeNone;
pField.autocorrectionType = UITextAutocorrectionTypeNo;
pField.keyboardType = UIKeyboardTypeDefault;
pField.returnKeyType = UIReturnKeyDone;
pField.delegate = self;
pField.placeholder = @"tap to enter text";
// add label and textField to the header view
[headerView addSubview:pLabel];
[headerView addSubview:pField];
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 50.0;
}
#pragma mark TextField Delegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
// dismiss the keyboard
[textField resignFirstResponder];
return YES;
}
#pragma mark Memory Management
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
}
- (void)viewDidUnload
{
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.table = nil;
}
- (void)dealloc
{
[table release];
[array release];
[super dealloc];
}
@end
クラッシュするには、iOS 4.1 を搭載したデバイスで実行し、次の手順に従います。
- テキストフィールドを編集する
- キーボードを閉じる
- 行をスワイプして削除
- 削除ボタンをタップ
- クラッシュ!
この問題をご覧いただきありがとうございます。