Ios UITableView始终处于普通模式,尽管在XIB中另有定义

Ios UITableView始终处于普通模式,尽管在XIB中另有定义,ios,uitableview,Ios,Uitableview,我使用新建文件对话框中的UITableViewController选项,使用预设创建了一个UITableView。我使用界面生成器将样式设置为“分组” 但是,该表始终以普通样式显示 数据源由两个部分组成,每个部分有两个项目和一个部分标题。这一切都显示不错,但风格是错误的。通过NSLog我验证了样式在运行时确实设置为plain。我错过什么了吗 编辑:这是我的代码。正如我提到的,NSLog调用返回预期值 @implementation EventTableView @synthesize tabl

我使用
新建文件
对话框中的
UITableViewController
选项,使用预设创建了一个
UITableView
。我使用界面生成器将样式设置为“分组”

但是,该表始终以
普通样式显示

数据源由两个部分组成,每个部分有两个项目和一个部分标题。这一切都显示不错,但风格是错误的。通过
NSLog
我验证了样式在运行时确实设置为plain。我错过什么了吗

编辑:这是我的代码。正如我提到的,
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
编辑:为了提供帮助,我添加了
界面生成器
(样式设置为
)的屏幕截图。

更新:

发现


在控制器中,在那里设置
style=UITableViewStyleGroupedsuper

之前,如果没有任何代码调用视图的
-(id)initWithStyle:(UITableViewStyle)style
方法时使用了错误的样式(我有点期待), 您可以将init方法重写为

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

不过,首先,您可能会尝试确保已将.xib保存在Xcode中,清理并重建应用程序,以便确保您所做的更改是设备/模拟器上实际运行的内容

那太疯狂了。我找到了一种工作

我添加了一个标准的
UIViewController
,并在其上实现了协议
UITableViewDelegate
UITableViewDataSource

在XIB/NIB中,我删除了标准的
UIView
,并添加了
UITableView
。我将视图的outlets
datasource
delegate
连接到文件所有者对象,将文件所有者的视图outlets连接到
UITableView


现在我可以将表格的样式设置为“分组”。到目前为止,一切都很顺利。但是,我不明白使用
UITableViewController有什么不同

请显示一些代码。如何在应用程序中实例化tableview?由于对象来自XIB,因此我没有真正实例化任何内容…仍然没有:-)此init方法不可用。我检查了所有可用的init方法并添加了一个NSLog。没有人被叫。我猜是因为对象是从NIB/XIB反序列化的。很抱歉,但您确定是从该.XIB文件加载的吗?)并检查此项-文件的所有者
tableView
outlet是否连接到您的表?实现方法
-(void)awakeFromNib
,并在那里设置断点。调试会到此为止吗?让我们不要抱歉。如前所述,我检查了所有可用的init方法并添加了一个NSLog。没有人被叫。我猜是因为对象是从NIB/XIB反序列化的。那么您是否尝试更改init方法?并且您没有另一个.XIB,它可能是加载的方法?奇怪的问题。
- (id)initWithStyle:(UITableViewStyle)style
{
   self = [super initWithStyle:UITableViewStyleGrouped];
   return self;
}