我有一个奇怪的问题,我找不到解决方案(或类似的东西)。问题是,我的 UITableView 填充了初始信息(用于测试),但无论我做什么,我似乎都无法将其设置为分组样式(我可以在 UI 上选择它,但它不会显示)
我最初启动了一个 TabBar 项目,并在选项卡中添加了第三个 navigationController 视图。
#import <UIKit/UIKit.h>
@interface RootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
NSMutableArray *tableData;
}
@property (nonatomic, retain) NSMutableArray *tableData;
-(void)initTableData;
@end
这是标题,如您所见,它没有任何异常。以下代码位于我刚刚发布的标头的 .m 文件中(只会发布未注释的代码:
@synthesize tableData;
-(void)initTableData
{
tableData = [[NSMutableArray alloc] init];
[tableData addObject:@"Cidade"];
[tableData addObject:@"Veículo"];
[tableData addObject:@"Ano"];
[tableData addObject:@"Valor"];
[tableData addObject:@"Cor"];
[tableData addObject:@"Combustível"];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Busca";
UIBarButtonItem *_backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:nil action:nil];
self.navigationItem.backBarButtonItem = _backButton;
[self initTableData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return 6;
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [tableData objectAtIndex:[indexPath row]];
return cell;
}
- (void)dealloc {
[tableData release];
[super dealloc];
}
如您所见,没有什么不寻常的事了……知道可能是什么原因造成的吗?我试过了
- (id)initWithStyle:(UITableViewStyle)style {
// Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
self = [super initWithStyle:UITableViewStyleGrouped];
if (self) {
// Custom initialization.
}
return self;
}
因为我不知道还能做什么。(也没有工作)再次,我将委托和数据源设置为文件的所有者。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Set the tab bar controller as the window's root view controller and display.
self.window.rootViewController = self.tabBarController;
RootViewController *rvc = [[RootViewController alloc] initWithStyle: UITableViewStyleGrouped];
[self.window makeKeyAndVisible];
return YES;
}