0

嗨,我有一个分组的表格视图,第一部分包含电子邮件列表,第二部分只有两行,手动添加电子邮件并从联系人中选择电子邮件。

ManualEmail.m 中的日志一直为计数记录 0,并且 EmailViewController 中的数组从未修改过,但我不知道出了什么问题

这是我目前的设置

电子邮件视图控制器.h

@property (nonatomic, retain) IBOutlet NSMutableArray *dataArray;

电子邮件视图控制器.m

@synthesize dataArray;

- (void)viewDidLoad {
    [super viewDidLoad];
    dataArray = [[NSMutableArray alloc] init];
    NSMutableArray *listItems = [[NSMutableArray alloc] initWithObjects:nil];
    [listItems addObject:[ObjectArrays productWithType:@"test" Eemail:@"test@website.com" Eselected:YES]];
    NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:listItems forKey:@"data"];
    [dataArray addObject:firstItemsArrayDict];
    NSArray *secondItemsArray = [[NSArray alloc] initWithObjects:@"Add Email Address From Contacts", @"Add Email Address Manually", nil];
    NSDictionary *secondItemsArrayDict = [NSDictionary dictionaryWithObject:secondItemsArray forKey:@"data"];
    [dataArray addObject:secondItemsArrayDict];
    [tableView reloadData];
}

手动电子邮件.m

    EmailViewController *emailPVC = [[EmailViewController alloc] init];
    NSDictionary *dictionary = [emailPVC.dataArray objectAtIndex:0];
    NSArray *array = [dictionary objectForKey:@"data"];
    NSMutableArray *emailArray = [NSMutableArray arrayWithArray:array];
    [emailArray addObject:[ObjectArrays productWithType:name.text Eemail:email.text Eselected:YES]];
    [emailPVC.dataArray removeObjectAtIndex:0];
    NSDictionary *firstItemsArrayDict = [NSDictionary dictionaryWithObject:emailArray forKey:@"data"];
    [emailPVC.dataArray insertObject:firstItemsArrayDict atIndex:0];
    NSLog(@"%d", [emailPVC.dataArray count]);
4

1 回答 1

0

在 ManualEmail.m 中,您正在创建EmailViewControllerin 代码。但是你从来没有调用任何会调用它的-viewDidLoad方法的东西,所以dataArray不会被创建或填充。你需要打电话emailPVC.view = <some view you created>;才能-viewDidLoad被叫到。

于 2013-03-30T15:55:12.347 回答