In the tableview the user can tap the upper right button (navigation bar rightside) and it will pop up the custom alert view and ask user to type in the edittext box with two button cancel and save. As you can see in the code below. When i click on save it will add a row and display ‘label’ to confirm that it is working and now i want to be able to display whatever the user typed in the box. I have read all the tableview apple developer site and search around and they all don’t do the way I want.
- (void) CustomAlertView:(CustomAlertView *)alert wasDismissedWithValue:(NSString *)value
{
[authorList addObject:@"label"];
[tblSimpleTable reloadData];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Delete the row from the data source.
[authorList removeObjectAtIndex:indexPath.row];
[tblSimpleTable reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert)
{
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
[authorList insertObject:@"label" atIndex:[authorList count]];
[tblSimpleTable reloadData];
}
}
UPDATE***
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Save"])
{
NSString *any = [NSString stringWithFormat:@"'%@'"];
[authorList addObject:any];
[tblSimpleTable reloadData];
}
}
insert row code
else if (editingStyle == UITableViewCellEditingStyleInsert)
{
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
NSString *any = [NSString stringWithFormat:@"'%@'"];
[authorList insertObject:any atIndex:[authorList count]];
//[authorList addObject:any];
[tblSimpleTable reloadData];
}
}
go to this link
http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
in alert view delegate methos u take the value of text
NSString *string = alertViews.textField.text;
and then reload table;