0

我有一个包含建筑信息(字符串)的建筑类。当我推动我的 DetailViewController(不是来自 tableviewcontroller)时,我推动了与它一起使用的建筑物,它加载了正确的信息。我想要做的是在下一个构建实例中加载的详细视图上有一个按钮。我尝试了以下但没有运气 - 所有数据都变为空白/空。我一定没有正确连接到我的建筑物阵列。

在我的 mainViewController

-(IBAction)pushDetailsVC:(id)sender {

    DetailViewController* controller = [[DetailViewController alloc] init]; 
    // Pass the Building object to the controller
    building = [self.buildings objectAtIndex:nsu_selBldg];
    controller.building = building;
    NSLog(@"Building name is now: %@", building);
    [self presentModalViewController:controller animated:YES];
    [controller.uib_backButton addTarget:self action:@selector(close:) forControlEvents:UIControlEventTouchUpInside];
    [controller release];
}

在我的 DetailViewController // h 中有

@property (nonatomic, retain) Building *building;
@property (nonatomic, retain) PhotoViewerViewController *photoVC;

//m 有

- (void)viewDidLoad
{
    [super viewDidLoad];
    // This works as expected - the data loads in great.
    self.uill_bldgName.text = self.building.name;
    self.uitt_bldgInfo.text = self.building.bldgInfo;
    self.uiivv_bldgPlan.image = [UIImage imageNamed:self.building.bldgPlan];
    self.uiivv_bldgImage.image = [UIImage imageNamed:self.building.bldgImageZoom];
    NSLog(@"first name%@",self.building.bldgImageZoom);
}

-(IBAction)nextBldg {
    // This does not work - data goes null. PhotoVC is my main view controller and buildings is the array of buildings
    building = [photoVC.buildings objectAtIndex:2];
    Building *building = building;
    NSLog(@"building %@",building);
    NSLog(@"building %@",[photoVC.buildings objectAtIndex:2]);  
    self.uill_bldgName.text = self.building.name;
    self.uitt_bldgInfo.text = self.building.bldgInfo;
    self.uiivv_bldgPlan.image = [UIImage imageNamed:self.building.bldgPlan];
    self.uiivv_bldgImage.image = [UIImage imageNamed:self.building.bldgImageZoom];
    NSLog(@"secon name %@",self.building.bldgImageZoom);    
}
4

1 回答 1

1

我看不到您在哪里初始化 photoVC。没有初始化,你肯定没有建筑数据。

更好的方法是将构建数组(和当前索引 nsu_selBldg)传递给 DetailViewController。然后它将可以访问它想要的任何建筑物。

// DetailVC.h

@property (nonatomic, retain) NSArray *buildings;
@property (nonatomic, assign) NSUInteger currentIndex;

// DetailVC.m

Building *currentBuilding = [self.buildings objectAtIndex:self.currentIndex];
NSUInteger nextIndex = (self.currentIndex == self.buildings.count-1)? 0 : self.currentIndex+1;
Building *nextBuilding = [self.buildings objectAtIndex:nextIndex];
于 2012-04-05T00:14:13.687 回答