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

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex