I am using a UITableView to show data, and by using customise button and delete function I am trying to delete selected row. But i want to put an alertview inside that function when UITableView is empty, and by using buttons inside the UIAlertView I am trying to navigate to main page and previous page according to conditions. But it’s getting crashed after UITableView is getting empty and I push the delete button with “Program received signal: “SIGABRT”.
My code looks like this:
- (IBAction)DeleteButtonAction:(id)sender
{
DMSAppDelegate *d = (DMSAppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"Message From Custom Cell Received");
if(d->newtableData.count != 0)
{
NSIndexPath *indexPath = [self.tablevieww2 indexPathForCell:(UITableViewCell *)[[[sender superview] superview] superview]];
NSUInteger row = [indexPath row];
[d->newtableDataQt removeObjectAtIndex:row];
NSLog(@"data removed");
[self.tablevieww2 reloadData];
}
else
{
UIAlertView *alertview=[[UIAlertView alloc] initWithTitle:@"hello" message:@"Warning!!: Table is empty" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"",@"No",nil];
textfieldQty1 = [alertview textFieldAtIndex:0];
textfieldQty1.keyboardType = UIKeyboardTypeNumberPad;
textfieldQty1.keyboardAppearance = UIKeyboardAppearanceAlert;
textfieldQty1.autocorrectionType = UITextAutocorrectionTypeNo;
[alertview show];
[alertview release];
}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
DMSViewController *bt=[[DMSViewController alloc]initWithNibName:nil bundle:nil];
bt.modalTransitionStyle=UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:bt animated:YES];
}
else if (buttonIndex == 1)
{
NSString *newqty = [[NSString alloc] initWithFormat:@"%@",textfieldQty1.text];
DMSAppDelegate *d= (DMSAppDelegate *)[[UIApplication sharedApplication] delegate];
[d->newtableDataQt replaceObjectAtIndex:slCell1 withObject:(id)newqty];
NSLog(@"tb%@",d->newtableDataQt);
[self.tablevieww2 reloadData];
int total1=0;
for ( int i=0 ; i < [d->newtableDataQt count];++i )
{
NSString *string = [d->newtableDataQt objectAtIndex:i];
NSLog(@"string%@",string);
if ([string isEqualToString:@"0"])
{
}
else
{
NSLog(@"newArray%@",d->newtableDataPrice);
NSString *strP=[d->tableDataPrice objectAtIndex:i];
NSInteger sp=[strP integerValue];
NSInteger st=[string integerValue];
total1=total1+st*sp;
NSLog(@"total1%d",total1);
}
}
NSString *newtotal1=[NSString stringWithFormat:@"%d",total1];
DMSAppDelegate *d2 = (DMSAppDelegate *) [[UIApplication sharedApplication] delegate];
d2->totalD = [[NSString alloc] initWithString:newtotal1];
}
}
Please give me some solution. I am trying really hard from yesterday but not getting any success.
Thanks in advance.
@
You need to check two things:-
First:-
if(d->newtableData.count != 0)is the condition and you are not removing the items from
newtableDatayou are removing it fromnewtableDataQtso thats why your else method is not getting called. becausenewtableDatawill never have count =0.Second thing;-
one thing if your table is empty means that
newtableDataQtwill contain no values , it will be empty.Now when you click on the delete button, the alert view appears , after that if you click whatever button at index 1 then in your code you have written :-so
newtableDataQthas already be empty before and now you are using it.This might be the reason of crash.try
I hope it might help you.