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
로 설정 스타일)의 스크린 샷을 포함했다.
약간의 코드를 보여주세요. 앱에서 tableview를 어떻게 인스턴스화합니까? – uvesten
개체가 XIB에서 오는 것처럼 아무 것도 실제로 인스턴스화하지 않습니다 ... – spa