将UITextField的内容添加到NSMutableArray

时间:2012-04-06 06:32:22

标签: objective-c cocoa-touch ios5 nsmutablearray

如何将UITextField中的元素放入NSMutableArray

3 个答案:

答案 0 :(得分:3)

//Array should be of mutable type NSMutableArray *yourArray=[NSMutableArray alloc]init];

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [yourArray addObject:[textfield text]];
    NSLog([yourArray description],nil);
}

答案 1 :(得分:1)

您可以从文本字段中提取文本:

-(void)textFieldDidEndEditing:(UITextField *)textField{

     NSString *lTemp = textField.text;

     //Add to your array
     [lMutableArray addObject: lTemp];
  }

答案 2 :(得分:0)

检查来自here的代码,我在这里添加了在View上显示的NSMutableArray中所有文本字段的文本值。