0

我创建了三个文本字段食物名称、食物数量、钠量。当我单击提交按钮时,我想使用文本字段中的数据更新表格视图。我创建了一个 NSObject 并建立了日志以显示数据正在从文本字段中保存,并且提交将移至表格视图,但我无法从文本字段中获取数据以显示

@interface FoodContents : NSObject
{
    NSString *myFoodName;
    NSString *myFoodQuanity;
    NSString *mySodiumAmount;
}

@property (strong,nonatomic) NSString * myFoodName;
@property (strong,nonatomic) NSString * myFoodQuanity;
@property (strong,nonatomic) NSString * mySodiumAmount;

-(id)initWithTitle:(NSString *)foods quanity:(NSString *)foodCount salt:(NSString           *)saltAmount;



- (IBAction)submitOnClick:(id)sender
{

 FoodContents *test = [[FoodContents alloc] initWithTitle:[NSString       stringWithFormat:@"%@",   foodName.text] quanity:[NSString stringWithFormat:@"%@",foodQuanity]   salt:[NSString stringWithFormat:@"%@",sodiumAmount.text]];
[textfieldData addObject:test];
NSLog(@"%@", textfieldData);

FoodListViewController * third_viewController = [[FoodListViewController alloc]  initWithNibName:@"FoodListViewController" bundle:nil];
  if (third_viewController != nil)
{
    third_viewController.foodDetails = test;
    //[self.textfieldData addObject:[NSString stringWithFormat:@"%@",     self.foodName.text]];
    //[self.textfieldData addObject:[NSString stringWithFormat:@"%@", self.foodQuanity.text]];
    //[self.textfieldData addObject:[NSString stringWithFormat:@"%@", self.sodiumAmount.text]];

    NSLog(@"%@",textfieldData);
    [self presentViewController:third_viewController animated:true completion:nil];
}

}

4

0 回答 0