开发者

How To Add The Data From an Alert View To my Table

I Have Created a Table With some list of options and one of it is "ADD NEW ROW".If the user clicks on it he will get an alert view.i have customized that alert view with a text field.But the problem is i am not able to add that data entered in the text field to my table view.

Some one pls help.

 - (void)tableView:(UITableView *)aTableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{ 

if (editingStyle == UITableViewCellEditingStyleDelete)
{
    [self.listOfCategories removeObjectAtIndex:indexPath.row];
    [self.tableViewC reloadData];
} 
else if (editingStyle == UITableViewCellEditingStyleInsert)
{
    UIAlertView *myAlertView = [[UIAlertView 开发者_StackOverflowalloc] initWithTitle:@"Your title here!" message:@"...." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0,    260.0, 25.0)];
    [myTextField setBackgroundColor:[UIColor whiteColor]];
    [myAlertView addSubview:myTextField];
    [myAlertView show];
    [myAlertView release];
    [self.listOfCategories insertObject:@"Add" atIndex:[self.listOfCategories count]];
    [self.tableViewC reloadData];
}


in you alertView Delegate write this code..

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
      if(buttonIndex==0)
        {
               NSIndexPath *newPath = [NSIndexPath indexPathForRow:yourArray.count inSection:0];
               [yourArray insertObject:[NSString stringWithFormat:@"%@",yourTextField.text] atIndex:newPath.row];
               [tableView reloadData];
        }
    }


Don't think of it as adding a row to your table view. Think of it as adding an entry to your datasource. How are you storing your data? If it is an array, add the object to the array then reload your table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜