我正在开发一个联系人应用程序。我想通过打开这样的新视图来添加联系人:
RootViewController.m... 它有一个 NSMutableArray 称为联系人
- (IBAction)addContact:(id)sender {
AddContViewController *cont = [[AddContViewController alloc]init];
[self.navigationController presentViewController:cont animated:YES completion:nil];
}
然后回来将联系人添加到根视图控制器的数组中:
添加ContViewController.m
- (IBAction)acceptAction:(id)sender {
if ([[firstName text] length] < 1 && [[lastName text] length] < 1)
{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Oh no!" message:@"Invalid contact information!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}
else{
// 创建联系人并将其放入根视图控制器的数组中
Contact *cont = [[Contact alloc]initWithFirstName:[firstName text] lastName:[lastName text] andDOB:[dobPicker date]];
// 现在我不知道该怎么办....
[self dismissViewControllerAnimated:YES completion:^{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Success!" message:@"Contact added successfully!" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alert show];
}];
}
}