我已成功将muscleName项加载到表视图中,但是没有运气将其各自的exerciseName加载到第二个表视图中。
我使用的方法是:
cell.textLabel.text = [[self.exerciseArray objectAtIndex:indexPath.row] objectForKey: @"exerciseName"];
也许我需要定义常量?
编辑:
以下是ViewDidLoad中第一个加载muscleName的表的代码:
if (muscleArray == nil)
{
//Read the plist file into an array (the root element is an array)
NSString *path = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"plist"];
NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.muscleArray = rootLevel;
[rootLevel release];
这是我当前的子表类
import "SpecificExerciseTableViewController.h"
#import "MusclesTableViewController.h"
#import "CurlAppDelegate.h"
#import "DetailViewController.h"
@implementation SpecificExerciseTableViewController
@synthesize exerciseArray;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
}
return self;
}
- (void)dealloc
{
[exerciseArray release];
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
self.navigationItem.title = @"Exercises";
[super viewDidLoad];
if (exerciseArray == nil)
{
//Read the plist file into an array (the root element is an array)
NSString *path = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"plist"];
NSMutableArray *rootLevel = [[NSMutableArray alloc]initWithContentsOfFile:path];
self.exerciseArray = rootLevel;
[rootLevel release];
}
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.exerciseArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [[self.exerciseArray objectAtIndex:indexPath.row]objectForKey:@"exerciseName"];
return cell;
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tv accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellAccessoryDisclosureIndicator;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Navigation logic may go here. Create and push another view controller.
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
// ...
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
@end
答案 0 :(得分:0)
如果您没有看到更多代码,那么如果您从exerciseName
开始,看起来您正在访问exercises
属性。
您确定self.exerciseArray
指向您的exercises
对象吗?最快捷的检查方法就是放入NSLog()
语句,看看你是否拥有自己的想法:
NSLog(@"Exercises: %@", self.exerciseArray);