views:

69

answers:

1

I have made some progress and am editing the question to be current again. My big issue now is that the grouped table view will load, but shows all of everything in each section with each row. Also, my UIAlertView is returning all references to my plist (null). How would I fix this because the references to the plist are killing me. Any and all help would be greatly appreciated!

Here is the plain text version of my plist file:

<array>
<dict>
    <key>eventName</key>
    <string>Comedy Caravan</string>
    <key>eventSpecifics</key>
    <string>Nicholas Anthony</string>
    <key>eventLocation</key>
    <string>The Cats Den</string>
    <key>eventType</key>
    <string>Comedy</string>
    <key>eventGoodies</key>
    <string>Both</string>
    <key>eventDate</key>
    <date>2010-07-23T00:00:00Z</date>
</dict>
<dict>
    <key>eventName</key>
    <string>Comedy Caravan</string>
    <key>eventLocation</key>
    <string>The Cats Den</string>
    <key>eventType</key>
    <string>Comedy</string>
    <key>eventSpecifics</key>
    <string>Bruce Baum</string>
    <key>eventGoodies</key>
    <string>Prizes</string>
    <key>eventDate</key>
    <date>2010-07-24T00:00:00Z</date>
</dict>
<dict>
    <key>eventName</key>
    <string>Late Night Film Series</string>
    <key>eventLocation</key>
    <string>The Cats Den</string>
    <key>eventType</key>
    <string>Comedy</string>
    <key>eventSpecifics</key>
    <string>Avatar</string>
    <key>eventGoodies</key>
    <string>Food</string>
    <key>eventDate</key>
    <date>2010-07-24T02:00:00Z</date>
</dict>
</array>

Here is my ThisWeekViewController.h:

#import <UIKit/UIKit.h>

@class Event;

@interface ThisWeekViewController : UITableViewController

{
NSArray *eventNames;
Event *event;
}

@property (nonatomic, retain) NSArray *eventNames;
@property (nonatomic, retain) Event *event;

@end

and Here is my ThisWeekViewController.m:

#import "ThisWeekViewController.h"
#import "Event.h"

@implementation ThisWeekViewController

@synthesize eventNames;
@synthesize event;


- (void)viewDidLoad {
    [super  viewDidLoad];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Events" ofType:@"plist"];
    NSArray *dict = [[NSArray alloc] initWithContentsOfFile:path];

    NSArray *namesArray = [dict valueForKey:@"eventName"];
    self.eventNames = namesArray;
    [dict release];

    [self.tableView reloadData];    
}



- (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.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    self.eventNames = nil;
}


#pragma mark Table View Methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return [self.eventNames count];
}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *key = [NSString stringWithFormat:@"%@", event.eventName];
    return key;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.eventNames count];
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSUInteger row = [indexPath row];

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell.

    // Set the cell's text to the event name
    cell.textLabel.text = event.eventName;

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}


- (void)dealloc {
//  [thisWeek release];
    [event release];
    [eventNames release];
    [super dealloc];
}


@end

I have also included my Event.h file

 #import <Foundation/Foundation.h>


@interface Event : NSObject {
    NSString *eventName;
    NSString *eventType;
    NSDate *eventDate;
    NSString *eventLocation;
    NSString *eventGoodies;
    NSString *eventSpecifics;

}

- (id)initWithDictionary:(NSDictionary *)aDictionary;

@property (nonatomic, retain) NSString *eventName;
@property (nonatomic, retain) NSString *eventType;
@property (nonatomic, retain) NSString *eventLocation;
@property (nonatomic, retain) NSDate *eventDate;
@property (nonatomic, retain) NSString *eventGoodies;
@property (nonatomic, retain) NSString *eventSpecifics;

@end

and my Event.m file

 #import "Event.h"


@implementation Event

@synthesize eventName;
@synthesize eventType;
@synthesize eventDate;
@synthesize eventLocation;
@synthesize eventGoodies;
@synthesize eventSpecifics;

- (id)initWithDictionary:(NSDictionary *)aDictionary {
    if ([self init]) {
        self.eventName = [aDictionary valueForKey:@"eventName"];
        self.eventType = [aDictionary valueForKey:@"eventType"];
        self.eventDate = [aDictionary valueForKey:@"eventDate"];
        self.eventLocation = [aDictionary valueForKey:@"eventLocation"];
        self.eventGoodies = [aDictionary valueForKey:@"eventGoodies"];
        self.eventSpecifics = [aDictionary valueForKey:@"eventSpecifics"];

    }
    return self;
}

- (void)dealloc {
    [eventName release];
    [eventType release];
    [eventDate release];
    [eventLocation release];
    [eventGoodies release];
    [eventSpecifics release];

    [super dealloc];
}

@end

I would like to be able to place things such as cell.detailTextLabel.text = event.eventSpecifics and just run off of references like that.

A: 

If I recall correctly, UITableViewController reloads the table view in -viewWillAppear:. This may very well be called before -viewDidLoad is called. I would recommend that you insert a call to [self.tableView reloadData] at the end of your implementation of -viewDidLoad.

You should also be calling [super viewDidLoad] at the top of your implementation of -viewDidLoad, and similarly for -viewDidUnload.

Also, you don't need to declare your class as conforming to UITableViewDataSource or UITableViewDelegate as your superclass (UITableViewController) already does that for you.

Kevin Ballard
No, the viewDidLoad will be called first and be called only once. So, putting [self.tableView reloadData] into viewWillAppear: is more accurate
vodkhang
There is no guarantee that `viewDidLoad` is called before `viewWillAppear:`, and in fact it's pretty easy to prove that this is the case. Create a UIViewController subclass that logs both methods, and push it onto a nav stack. Last time I tested, UINavigationController calls `viewWillAppear:` before it ever accesses the view and triggers `viewDidLoad`.
Kevin Ballard
I added all of the suggestions from Kevin Ballard and the table view is still empty. I also added: -(void)viewWillAppear:(BOOL)animated { //Force the tableview to load [self.tableView reloadData]; }according to vodkhang and the table view is still empty. Any other errors in the code that you may see?
Branden A
Have you tried logging the value of keys? You should also switch to using `self.keys` instead of `keys`, but that isn't the cause of your problem here. You should try logging `keys` in `-numberOfSectionsInTableView:` and see what it contains.
Kevin Ballard