我有一个故事板,它使用自定义的UIViewcontroller(我们称之为VC-A),它的根视图中包含两个容器视图控制器。我希望VC-A在初始化期间收集一些数据,并在初始化期间将其传递给其中一个子vc。我猜测我完全不理解这种工作的正确流程,因为它似乎不可能。我可以设置值并运行覆盖initWithCoder方法的其他操作,并将VC-A设置为其他子vc的委托(我可以将VC-A设置为子vc的委托和子代) vc可以查询vc-a以获取数据,但这只能在子vc初始化之后发生)。有没有办法做到这一点?或者更有可能我在哪里错过了正确的信息流?谢谢你的阅读!
在VC-A
中-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"collectionEmbed"]) {
}
if ([segue.identifier isEqualToString:@"tableEmbed"]) {
ImageTableViewController *utvC = (ImageTableViewController *)segue.destinationViewController;
[utvC setUnitArray:[self vendUnitList]];
//A check on the debugger here shows that [[self vendUnitList] count] returns 5
}
}
在VC-B中(TableViewController的子类
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
NSLog(@"%u",self.unitArray.count);
//Debugger shows this to be 0
return self.unitArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
UnitVO *unitVO = (UnitVO *)[unitArray objectAtIndex:indexPath.row];
NSLog(@"Unit Name: %@",unitVO.unit_name);
cell.textLabel.text = unitVO.unit_name;
return cell;
}
一些登录'
- (void)viewDidLoad
{
[super viewDidLoad];
if(self.tableView.delegate == self && self.tableView.dataSource == self)
{
NSLog(@"Yep");
}else{
NSLog(@"Nope");
}
// Get Yep for output
}
故事板可以在这里看到:1
答案 0 :(得分:1)
为什么不在VC-A中使用它来设置VC-B中的值
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
[segue.destinationViewController setSomeValue:_someValue];
}
希望我能正确理解这个问题。