いくつかのセルが入力されているUITableViewがあります。次のスニペットを使用してUIButtonを作成しました。これは、セクションヘッダーの1つの横に配置されています。
UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
[addButton addTarget:self action:@selector(addButtonPressed) forControlEvents:UIControlEventTouchUpInside];
[addButton setBackgroundImage:[UIImage imageNamed:@"add.png"] forState:UIControlStateNormal];
addButton.backgroundColor = [UIColor clearColor];
addButton.frame = CGRectMake(270, 150, 29, 29);
ボタンが配置され、正しく機能します。ただし、ビューがスクロールされた後(1ピクセルのように少しでも)、ボタンは1回機能し、その後応答を停止します。クリックされたときのアクションに応答しない場合、ボタンはトリガーされず、ボタンは「押された」シャドウを表示しません。アプリケーションの残りの部分は通常どおり実行され、クラッシュしません。
スクロールした後、ボタンが機能しなくなる前にもう一度クリックできるため、これは奇妙に思えます。ボタンはテーブルに行を挿入するために使用されるので、ボタンを押すと余分な行があります。これは境界を超えているのでしょうか。
ボタンを押した機能:
- (void)addButtonPressed {
self.addClientTable.editing = YES;
// First figure out how many sections there are
NSInteger lastSectionIndex = [self numberOfSectionsInTableView:self.addClientTable] - 1;
// Then grab the number of rows in the last section
NSInteger lastRowIndex = [self.addClientTable numberOfRowsInSection:lastSectionIndex];
[self.addClientTable insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:lastRowIndex inSection:lastSectionIndex]] withRowAnimation:UITableViewRowAnimationRight];
self.addClientTable.editing = NO;
}
addClientTable
UITableViewはどこにありますか。
UIButtonがクリックへの応答を停止する原因は何でしょうか。また、シナリオのどこでこれが発生するのでしょうか。