我想在Firebase数据库中添加内容,但它不起作用。
在我的ViewController.m中,我认为这里有一个问题:
- (IBAction)addButtonDidTouch:(id)sender {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Grocery Item" message:@"Add an Item" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UITextField *textField = alert.textFields[0];
GroceryItem *groceryItem = [[GroceryItem alloc]initWithName:textField.text byUser:self.user.email completed:false withKey:@""];
Firebase *groceryItemRef = [[Firebase alloc ]childByAppendingPath:textField.text.lowercaseString];
[groceryItemRef setValue:groceryItem.toAnyObject];
}];
UIAlertAction *cancelAlert = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"You was cancel");
}];
[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
[alert addAction:saveAction];
[alert addAction:cancelAlert];
}];
[self presentViewController:alert animated:true completion:nil]; }
当点击按钮添加并输入文字时,我点击SAVE ..它不起作用 请观看我的图片