无法将字符串添加到可变数组中

时间:2015-07-05 13:53:53

标签: objective-c nsmutablearray

我正在尝试将分配上传到不同视图控制器中的表中。首先,当我点击上传按钮时,此代码会运行。

- (IBAction)uploadAssignment:(id)sender {
    nameOfAssignmentAsString = self.nameOfAssignment.text;
    NSLog(@"%@", nameOfAssignmentAsString);
    NSInteger row;
    row = [self.subjectPicker selectedRowInComponent:0];
    subjectOfAssignmentAsString = [subjectArray objectAtIndex:row];
    NSLog(@"%@", subjectOfAssignmentAsString);
    NSDate *deadline = [self.deadlinePicker date];
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
    [dateFormat setDateFormat:@"dd/MM/yyyy"];
    deadlineOfAssignmentAsString = [dateFormat stringFromDate:deadline];
    NSLog(@"%@",deadlineOfAssignmentAsString);

    HomeworkViewController *HVC;
    [HVC.nameOfAssignmentInAnArray addObject:nameOfAssignmentAsString];
    [HVC.SubjectOfAssignmentInAnArray addObject:subjectOfAssignmentAsString];
    [HVC.deadlineOfAssignmentInAnArray addObject:deadlineOfAssignmentAsString];
    NSLog(@"%@",HVC.nameOfAssignmentInAnArray.count);
}

然后在我的HomeworkViewController.h中这是代码

@interface HomeworkViewController : UIViewController <UIGestureRecognizerDelegate,UITableViewDataSource,UITableViewDelegate> {

    int i;
}
@property (strong, nonatomic) IBOutlet UIView *mainMenu;
@property (strong, nonatomic) IBOutlet UIButton *homeworkButton;
@property (strong, nonatomic) IBOutlet UIButton *uploadButton;
@property (strong, nonatomic) NSMutableArray *nameOfAssignmentInAnArray;
@property (strong, nonatomic) NSMutableArray *SubjectOfAssignmentInAnArray;
@property (strong, nonatomic) NSMutableArray *deadlineOfAssignmentInAnArray;

我在HomeworkViewController.m文件中初始化它。但由于某种原因,字符串没有被添加到数组中。

1 个答案:

答案 0 :(得分:0)

您声明HVC但从不为其分配值。因此,它本身无法容纳任何东西。但由于某种原因,Objective-C的设计者认为向nil对象发送消息并不是一个错误,因此可能不会注意到这一点。