Я сделал некоторый прогресс и редактирую вопрос, чтобы быть снова. Моя большая проблема сейчас в том, что сгруппированное представление таблицы будет загружаться, но показывает все в каждом разделе с каждой строкой. Кроме того, мой UIAlertView возвращает все ссылки на мой plist (null). Как бы исправить это, потому что ссылки на plist убивают меня. Любая помощь будет принята с благодарностью!Почему мой plist не заполняет мой UITableView?
Вот обычная текстовая версия моего Plist файла:
<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>
Вот мой 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
и вот мой 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
Я также включил файл Event.h
#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
и мой файл Event.m
#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
Я хотел бы быть в состоянии поместить вещи, такие как cell.detailTextLabel.text = event.eventSpecifics
и просто убегают ссылок, как это.
Нет, viewDidLoad будет вызываться первым и вызываться только один раз. Итак, добавив [self.tableView reloadData] в viewWillAppear: более точно – vodkhang
Нет гарантии, что 'viewDidLoad' вызывается до' viewWillAppear: ', и на самом деле довольно легко доказать, что это так. Создайте подкласс UIViewController, который регистрирует оба метода и выталкивает его в стек nav. В прошлый раз, когда я тестировал, UINavigationController вызывает 'viewWillAppear:' перед тем, как он когда-либо обратится к представлению и запускает 'viewDidLoad'. –
Я добавил все предложения от Кевина Балларда, и табличный вид все еще пуст. Я также добавил: - (Недействительными) viewWillAppear: (BOOL) анимированный { \t // Принудительно TableView загрузить \t [self.tableView reloadData]; } в соответствии с водхангом, а вид стола по-прежнему пуст. Какие-либо другие ошибки в коде, который вы видите? –