Я создал UITableView
, используя предустановки, используя опцию UITableViewController
в диалоговом окне New File
.Я установил стиль для группировки с помощью Interface Builder.
Однако таблица всегда отображается в 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
).