0

单击添加按钮时,如何向 uitableview 的预定义数组添加新值?

-(IBAction)addNewBreed:(id)sender
{
    UIAlertView *addAlert=[[UIAlertView alloc]initWithTitle:@"Add New Item" message:@"\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Add",nil];
    UITextField *addTextField=[[UITextField alloc]initWithFrame:CGRectMake(12,45,260,25)];
    [addTextField becomeFirstResponder];
    [addTextField setBackgroundColor:[UIColor whiteColor]];
    addTextField.clearButtonMode=UITextFieldViewModeWhileEditing;
    [addAlert addSubview:addTextField];

    [addAlert show];


}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{

    NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];

    if ([buttonTitle isEqualToString:@"Add"]) 
    {

         //HERE WHAT CODE SHOULD I ADD,MY ARRAY NAME 'ar'       
    }
    else
        return;
}  
4

1 回答 1

0

如果您的数组是 a NSMutableArray,那么您可以使用以下代码:

[ar addObject: addTextField.text];//you may also enter any string here
  [yourTableView reloadData];
于 2012-08-11T06:16:26.983 回答