I have a table view, with an added headerview created in IB to display some text above the table (couldn’t post the screenshot- http://i51.tinypic.com/2przbl5.jpg). I would like to load the text above the table based on my plist and I am using objectforkey to load the text. However when I connect the outlets in IB the text disappears. This worked in a standard UIview so I’m not sure what I’m missing in the table view. I’m new to coding so perhaps there a better way to do this or what am i doing wrong? thanks.
.h file _________________________________________________
#import <UIKit/UIKit.h>
@interface TourOverviewController : UITableViewController {
NSArray *points;
NSDictionary *tour;
IBOutlet UITextField *nameTextField;
IBOutlet UITextView *pointsTextView;
}
@property (nonatomic, retain) NSArray *points;
@property (nonatomic, retain) NSDictionary *tour;
@property (nonatomic, retain) UITextField *nameTextField;
@property (nonatomic, retain) UITextView *pointsTextView;
@end
.m file______________________________________________________
#import "TourOverviewController.h"
#import "LoadingNames.h"
@implementation TourOverviewController
@synthesize points, tour, nameTextField, pointsTextView,
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
nameTextField.text = [tour objectForKey:NAME_KEY];
pointsTextView.text = [tour objectForKey:DIRECTIONS_KEY];
}
- (void)viewDidLoad {
NSArray *array = [[NSArray alloc] initWithObjects:@"Toy Story",
@"A Bug's Life", @"Toy Story 2", @"Monsters, Inc.",
@"Finding Nemo", @"The Incredibles", @"Cars",
@"Ratatouille", @"WALL-E", nil];
self.points = array;
[array release];
[super viewDidLoad];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [points count];
}
// Customize the appearance of table view cells.
- (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];
NSString *rowString = [points objectAtIndex:row];
cell.textLabel.text = rowString;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[rowString release];
return cell;
}
@end
Im not sure I understand your question but you could create 2 plists, points and tour and then fill your Mutable array and dictionary with the contents of the plist.
EDIT****************************
I missed this before, but maybe it as simple as adding a @” ” e.g.
You should make your array and dictionary mutable if you want to change the data within them for whatever reason.
Here is so code to get the plist and fill your array or dictionary(be sure to set the plists to the appropriate type when you fill them)
Put this in your viewDidLoad method
Then you have your array and dictionary filled with the contents of the plist.
Hope this helps, maybe I misunderstood want you want to do.