gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 23:12:57 31 4
gpt4 key购买 nike

我使用 New File 对话框中的 UITableViewController 选项使用预设创建了一个 UITableView。我使用 Interface Builder 将样式设置为分组。

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

数据源由两个部分组成,每个部分有两个项目和一个部分标题。一切都显示正常,但样式不对。通过 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

最佳答案

更新:

寻找

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style

在您的 Controller 中,在调用 super 之前设置 style = UITableViewStyleGrouped;

关于ios - UITableView 始终处于普通模式,尽管在 XIB 中另有定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7582086/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com