Skip to main content

Why does my AlertView takes 3 clicks on cancel button to close?



NOTE: I still don't have an answer to this:





I implemented a UIAlertView that displays a tableView to make a selection and return to the underlying view controller.





The alert view pops up fine, displays all the data and when I click the cancel button it does not respond, then I click it again and it moves position by quarter of an inch, then when I click it for the third time, the alertView finally disappears.





What would cause this type of behavior?





This is the code:







-(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];



}




Comments

  1. Perhaps you should be using SBTableAlertDatasource and SBTableAlertDelegate methods instead of the UITableViewDatasource and UITableviewDelegate methods.

    Also gesture is UILongPressGestureRecognizer. That is a continuous recognizer. You need to check for the state of the recognizer and ignore all the events that come after UIGestureRecognizerStateBegan

    ReplyDelete

Post a Comment

Popular posts from this blog

Why is this Javascript much *slower* than its jQuery equivalent?

I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.