如何在单击“添加”按钮时为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;
}
答案 0 :(得分:0)
如果您的数组是NSMutableArray
,那么您可以使用以下代码:
[ar addObject: addTextField.text];//you may also enter any string here
[yourTableView reloadData];