2011-09-28 2 views
0

New File 대화 상자에서 UITableViewController 옵션을 사용하여 사전 설정을 사용하여 UITableView을 만들었습니다. 인터페이스 빌더를 사용하여 스타일을 그룹화하도록 설정했습니다.UITableView는 항상 XIB에서 달리 정의되어 있지만 보통 모드입니다.

그러나 테이블은 항상 plain style에 표시됩니다.

데이터 원본은 각각 두 개의 항목과 섹션 헤더가있는 두 개의 섹션으로 구성됩니다. 그것 모두는 좋아 보인다. 그러나 스타일은 틀리다. NSLog을 통해 런타임에 스타일이 실제로 평범하게 설정되었는지 확인했습니다. 내가 놓친 게 있니?

편집 : 여기 내 코드. 앞에서 언급했듯이 NSLog 호출은 예상 값을 반환합니다.

@implementation EventTableView 

@synthesize tableView = _tableView; 

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:style]; 
    return self; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

#pragma mark - View lifecycle 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [[self navigationItem] setTitle:@"Events"]; 
    self.clearsSelectionOnViewWillAppear = YES; 

    NSLog(@"Table view style: %@.", (self.tableView.style == UITableViewStylePlain ? @"Plain" : @"Grouped")); 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
} 

- (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 
{ 
    if (_appDelegate == nil) { 
     _appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate]; 
    } 
    return _appDelegate.model.eventSections.count; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    Section* eventSection = [_appDelegate.model.eventSections objectAtIndex:section]; 
    NSInteger result = [eventSection getCountAsInteger]; 
    if (eventSection != nil && result >= 0) { 
     NSLog(@"Got %d rows in event section %d.", result, section); 
     return result; 
    } else { 
     NSLog(@"Can't get event section row count. Defaulting to 0."); 
     return 0; 
    } 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"EventCell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    // Configure the cell... 
    cell.textLabel.text = @"Test"; 
    return cell; 
} 

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{ 
    Section* eventSection = [_appDelegate.model.eventSections objectAtIndex:section]; 
    return eventSection.name; 
} 

#pragma mark - Table view delegate 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSLog(@"Pressed row..."); 
} 

@end 

편집 : 일을하기 위해, 나는 Interface Builder (group로 설정 스타일)의 스크린 샷을 포함했다. Interface Builder

+0

약간의 코드를 보여주세요. 앱에서 tableview를 어떻게 인스턴스화합니까? – uvesten

+0

개체가 XIB에서 오는 것처럼 아무 것도 실제로 인스턴스화하지 않습니다 ... – spa

답변

0

정말 대단합니다. 나는 일종의 일을 발견했다.

나는 UIViewController 표준을 추가했으며 프로토콜 UITableViewDelegateUITableViewDataSource을 구현했습니다.

XIB/NIB에서 UIView 표준을 제거하고 UITableView을 추가했습니다. 보기 콘센트 datasourcedelegate을 파일 소유자 개체에 연결하고 파일 소유자의보기 콘센트를 UITableView에 연결했습니다.

이제 그룹의 스타일을 설정할 수 있습니다. 지금까지 모든 것이 훌륭합니다. 그러나, 나는 진짜로 사용하는 것과 다른 것을 얻지 못한다. UITableViewController ...

1

업데이트 :

컨트롤러에
- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style 

찾기, 당신은 - (id)initWithStyle:(UITableViewStyle)style를 호출 어딘가에 코드가없는 경우 super

+0

아니요, 작동하지 않습니다. 읽기 전용 속성입니다. – spa

+0

업데이트 됨, 확인하십시오 – Nekto

+0

아직 아니요 :-)이 init 메소드를 사용할 수 없습니다. 사용 가능한 모든 init 메소드를 확인하고 NSLog를 추가했습니다. 아무도 불리지 않는다. 개체 NIB/XIB에서 deserialized 얻을 것 같아요. – spa

1

에 호출하기 전에이 style = UITableViewStyleGrouped; 설정 잘못된 스타일 (내가 예상하는 종류)로보기의 방법,

에 init 메소드를 다시 작성할 수
- (id)initWithStyle:(UITableViewStyle)style 
{ 
    self = [super initWithStyle:UITableViewStyleGrouped]; 
    return self; 
} 
먼저,하지만 당신은 당신이 확실 있도록 변경 사항은 무엇입니까 것을, 청소, 당신은 엑스 코드에서 .xib를 저장했는지 확인하고 응용 프로그램을 다시 시도 할 수 있습니다

실제로 장치/시뮬레이터에서 실행됩니다.

+0

죄송합니다. 언급했듯이 모든 사용 가능한 init 메소드를 검사하고 NSLog를 추가했습니다. 아무도 불리지 않는다. 개체 NIB/XIB에서 deserialized 얻을 것 같아요. – spa

+0

그런 다음 init 메소드를 변경하려고 했습니까? – uvesten

+0

예 ... 나는 한 번도 호출하지 않았으므로 효과가 없습니다 ... – spa

관련 문제