在我的 TableViewController 中,我设置了要在 DetailView (ws) 中加载的数据
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath sender:(id)sender{
detailViewController *detailVC = [[detailViewController alloc] init];
detailVC.ws = [self.tabAssociation objectAtIndex:indexPath.row];
[detailVC viewDidLoad] ;
//detailVC.descriptionTextView = [[UITextView alloc] init];
//[self.navigationController pushViewController:detailVC animated:YES];
}
这就是我的 DetailView 必须加载的内容
- (void)viewDidLoad
{
[super viewDidLoad];
self.barre.title = self.ws.associationName ;
self.descriptionTextView.text = self.ws.associationDescription ;
}
但是当我选择该行时,会出现一个白页而不是我的associationDescription 在文本视图中,我的associationName 也不是,但我的viewDidLoad 似乎在detailVC.ws 加载之前被调用,即我的detailVC 为空
这是我的 TableViewController.h
import UIKit/UIKit.h
@interface MasterViewController : UITableViewController{
NSArray *tabAssociation;
}
@property (nonatomic, retain) NSArray *tabAssociation;
@end
和 TableViewController.m
#import "MasterViewController.h"
#import "DetailViewController.h"
@interface MasterViewController () {
}
@end
@implementation MasterViewController
@synthesize tabAssociation ;
- (void)awakeFromNib
{
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSArray *dictFromFile = [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"AssociationTest" ofType:@"plist"]];
NSMutableArray *associationToAdd = [[NSMutableArray alloc] init];
NSEnumerator *enumerator = [dictFromFile objectEnumerator];
NSDictionary *anObject;
while ((anObject = [enumerator nextObject])) {
association *newAssocition = [[association alloc] initWithDictionaryFromPlist: anObject];
[associationToAdd addObject: newAssocition];
}
self.tabAssociation = [NSArray arrayWithArray:associationToAdd];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.tabAssociation.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// On récupère l'objet Website qui correspon à la ligne que l'on souhaite afficher
association *ws = [self.tabAssociation objectAtIndex:indexPath.row];
cell.textLabel.text = ws.associationName;
// On renvoie la cellule configurée pour l'affichage
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath sender:(id)sender{
detailViewController *detailVC = [[detailViewController alloc] init];
detailVC.ws = [self.tabAssociation objectAtIndex:indexPath.row];
//[detailVC viewDidLoad] ;
[self presentViewController:detailVC animated:YES completion:nil];
//detailVC.descriptionTextView = [[UITextView alloc] init];
//[self.navigationController pushViewController:detailVC animated:YES];
}
/*- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
NSDate *object = _objects[indexPath.row];
[[segue destinationViewController] setDetailItem:object];
}
}*/
@end