私はUIAlertViewを実装していました。このUIAlertViewはtableviewを表示して、選択を行い、背後のView Controllerに戻ります。私のAlertViewはキャンセルボタンを3回クリックして閉じるのはなぜですか?
アラートビューが正常に表示され、すべてのデータが表示されます。キャンセルボタンをクリックしても応答がない場合は、再度クリックして4分の1インチの位置を移動します。 alertViewが最後に消えます。
このような現象はどのような原因ですか?
これはコードです:
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if (indexPath == nil){
NSLog(@"long press on table view but not on a row");
}
else {
NSLog(@"long press on table view at row %d", indexPath.row);
selectedQuote = [self.quotes objectAtIndex:indexPath.row];
NSLog(@" subject title = %@", selectedQuote.title);
// NOW PULL UP THE ADD QUOTE MAP CONTROLLER SO THIS QUOTE CAN BE ADDED TO ANOTHER CATEGORY
if(aqmController == nil)
aqmController = [[AddQuoteMapController alloc] initWithNibName:@"AddQuoteMapController" bundle:nil];
aqmController.selectedQuote = self.selectedQuote;
//POP UP SBTableAlert
SBTableAlert *alert;
alert = [[SBTableAlert alloc] initWithTitle:@"Categorize this Quote" cancelButtonTitle:@"Cancel" messageFormat:@""];
[alert setType:SBTableAlertTypeMultipleSelct];
[alert.view addButtonWithTitle:@"OK"];
[alert.view setTag:0];
[alert setStyle:SBTableAlertStyleApple];
[alert setDelegate:self];
[alert setDataSource:self];
[alert show];
}
}
#pragma mark - SBTableAlertDataSource
- (UITableViewCell *)tableAlert:(SBTableAlert *)tableAlert cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell;
cell = [[[SBTableAlertCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
Category *cat = [categories objectAtIndex:indexPath.section];
Subject *sub = [cat.subjects objectAtIndex:indexPath.row];
cell.textLabel.text =sub.title;
cell.detailTextLabel.text = sub.category_title;
return cell;
}
- (NSInteger)tableAlert:(SBTableAlert *)tableAlert numberOfRowsInSection:(NSInteger)section {
Category *cat = [categories objectAtIndex:section];
return cat.subjects.count;
}
- (NSInteger)numberOfSectionsInTableAlert:(SBTableAlert *)tableAlert {
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
self.categories = [appDelegate categories];
return self.categories.count;
}
- (NSString *)tableAlert:(SBTableAlert *)tableAlert titleForHeaderInSection:(NSInteger)section {
Category *cat = [categories objectAtIndex:section];
NSString *title = [cat category_title];
return title;
}
#pragma mark - SBTableAlertDelegate
- (void)tableAlert:(SBTableAlert *)tableAlert didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Category *cat = [categories objectAtIndex:indexPath.section];
Subject *sub = [cat.subjects objectAtIndex:indexPath.row];
selectedSubject = sub;
NSLog(@"selectedSubject = %@", selectedSubject.title);
//INSERT INTO QUOTEMAP TABLE
// GET SUBJECT_ID
NSString *stringOfSubjectId = [NSString stringWithFormat:@"%d", selectedSubject.subject_id];
NSLog(@"mySubjectId= %@", stringOfSubjectId);
// GET THE NEXT QUOTE_MAP_ID
QuotesAppDelegate *appDelegate = (QuotesAppDelegate *)[[UIApplication sharedApplication] delegate];
QuoteMap *qm = [[QuoteMap alloc] init];
NSInteger newQuoteMapId = [appDelegate getNextQuoteMapId];
NSLog(@"quote_map_id= %d subId = %@ quoteId = %@", newQuoteMapId, stringOfSubjectId, selectedQuote.quote_id);
// INSERT INTO QUOTE_MAP TABLE
NSString *stringOfId = [NSString stringWithFormat:@"%d", newQuoteMapId];
qm.quote_map_id = stringOfId;
qm.subject_id = stringOfSubjectId;
qm.quote_id = selectedQuote.quote_id;
//qm.isDirty = YES;
[qm insertQuoteMap:qm];
//Add it to the array.
[qmv.quoteMaps addObject:qm];
[qmv.tableView reloadData];
if (tableAlert.type == SBTableAlertTypeMultipleSelct) {
UITableViewCell *cell = [tableAlert.tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone)
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
else
[cell setAccessoryType:UITableViewCellAccessoryNone];
[tableAlert.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
//release
[qm autorelease];
}
- (void)tableAlert:(SBTableAlert *)tableAlert didDismissWithButtonIndex:(NSInteger)buttonIndex {
NSLog(@"Dismissed: %i", buttonIndex);
[tableAlert release];
}
- (void)dealloc{
[qmv release];
[subjects release];
[categories release];
[selectedSubject release];
}
_alertViewの設定方法は? SBTableAlertとは関連するコードがたくさんあるようです。 – picciano
_alertViewがどこで設定されているかを示しました。 SBTableAlertはここに記述されています:[SBTableAlert](https://github.com/blommegard/SBTableAlert/blob/master/README.markdown) – jroyce
handleLongPressでは、ジェスチャ認識機能の 'state'プロパティをチェックする必要があります。認識装置によって複数回呼び出される。 http://stackoverflow.com/questions/8971237/uialertview-issue-iphone、http://stackoverflow.com/questions/3243812/uilongpressgesturerecognizer-issue、http://stackoverflow.com/questions/7688329/uilongpressgesturerecognizer-onを参照してください。 -uitableviewcell-double-callなど – Anna