2010-07-15 3 views
2

나는 약간의 진전을 이루었고 현재의 질문을 편집 중이다. 이제 큰 문제는 그룹화 된 테이블 뷰가로드되지만 각 섹션의 모든 내용이 각 행에 표시된다는 것입니다. 또한, 내 UIAlertView 내 plist (null)에 대한 모든 참조를 반환합니다. plist에 대한 언급이 나를 죽이고 있기 때문에 어떻게 해결할 수 있을까요? 모든 도움이 크게 감사하겠습니다! 여기 내 Plist가 내 UITableView를 채우지 않는 이유는 무엇입니까?

<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 
다음

내 PLIST 파일의 일반 텍스트 버전입니다

내 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 같은 것들을 배치하고 단지 같은 참조 떨어져 실행할 수 있도록하고 싶습니다.

답변

0

정확하게 다시 호출하면 UITableViewController은 테이블보기를 -viewWillAppear:에 다시로드합니다. 이것은 -viewDidLoad이 호출되기 전에 호출 될 수 있습니다. -viewDidLoad 구현의 마지막에 [self.tableView reloadData]에 전화를 걸도록하는 것이 좋습니다.

-viewDidLoad의 구현 상단에 [super viewDidLoad], 그리고 -viewDidUnload과 마찬가지로 전화해야합니다.

또한 클래스를 UITableViewDataSource 또는 UITableViewDelegate과 일치하도록 선언 할 필요가 없습니다. 수퍼 클래스 (UITableViewController)가 이미이를 수행하므로 클래스를 선언 할 필요가 없습니다.

+0

아니요, viewDidLoad가 먼저 호출되고 한 번만 호출됩니다. 따라서, [self.tableView reloadData]를 viewWillAppear :에 넣는 것이 더 정확하다. – vodkhang

+1

'viewWillAppear :'전에'viewDidLoad'가 호출된다는 보장은 없으며, 실제로 이것이 사실인지 증명하기가 쉽습니다. 두 메서드를 모두 기록한 UIViewController 하위 클래스를 만들고이를 nav 스택에 푸시합니다. 내가 테스트 한 마지막 시간에 UINavigationController는 뷰에 접근하고'viewDidLoad'를 트리거하기 전에'viewWillAppear :'를 호출합니다. –

+0

Kevin Ballard의 모든 제안을 추가했으며 테이블보기는 여전히 비어 있습니다. 또한 추가했습니다 : - (void) viewWillAppear : (BOOL) animated { \t // 강제로 테이블 뷰를로드합니다. \t [self.tableView reloadData]; } vodkhang에 따르면 테이블보기는 여전히 비어 있습니다. 코드에서 볼 수있는 다른 오류가 있습니까? –

관련 문제