2012-08-11 58 views
0

如何添加一個新值到預定義數組的uitableview,同時單擊添加按鈕?將值添加到預定義的數組爲uitableview iphone

-(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

你想在UITableView的一些具體指標添加對象? – 2012-08-11 06:19:58

回答

0

如果陣列是NSMutableArray,那麼你可以使用下面的代碼:

[ar addObject: addTextField.text];//you may also enter any string here 
    [yourTableView reloadData]; 
+0

我想要一個用戶輸入值嗎?請幫助@iPhone開發者 – fazil 2012-08-11 06:22:18

+0

我編輯了我的答案 – 2012-08-11 06:22:43

+0

非常感謝@iPhone Developer – fazil 2012-08-11 06:26:28

相關問題