0

我有一个奇怪的问题,我找不到解决方案(或类似的东西)。 事情是,我的UITableView填充初始信息(用于测试),但无论我做什么,我似乎都不能将它放到分组样式中(我可以在UI上选择它,但它不会显示)TableView委派,填充但不会组

我最初启动了一个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; 
} 

,因为我不知道自己还能做些什么。(也没有工作) 再说,我有设定为File`s业主的委托和数据源。

- (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; 
} 
+0

也许在同一张纸条上,我看起来似乎不会在点击表格后推动视图。 – Erakk 2012-04-17 12:54:37

回答

1

由于您已将- (id)initWithStyle:(UITableViewStyle)style初始值设定程序修改为以分组样式返回UITableView,因此在初始化RootViewController时是否调用此初始值设定项?

RootViewController *rvc = [[RootViewController] alloc] initWithStyle: UITableViewStyleGrouped]; 
+0

不会,那是appDelegate.m上的didFinishLaunching方法吗? 因为它已经将rootview设置为tabbar,并且让我感到困惑。 另外,我尝试推视图时,我单击表,但也没有发生。我猜我忘了一些非常基本的东西,因为我不是专家。 – Erakk 2012-04-17 13:04:48

+0

是的,你在哪里创建RootViewController。显示来自didFinishLaunching方法的代码。 – graver 2012-04-17 13:06:42

+0

我把代码放在主帖上,最后。 我是新手,所以,如果你发现一些愚蠢的错误,我很抱歉。 – Erakk 2012-04-17 13:23:21

1

分组表响应该部分。您只列出了1个部分,因此您只能看到1个组。尝试并为第二组添加第二个tableData并返回2个部分。您还必须将部分中的数据拆分为-cellForRowAtIndexPath,以确保数据进入正确的部分。

if (indexpath.section == 0) { 
    // first section and first tableData 
} 
if (indexpath.section == 1) { 
    // second section and second tableData 
} 
+0

没有工作,它只重复我的数据,但没有形成分组。 – Erakk 2012-04-17 13:19:11

+0

您的表格是否设置为分组表格?您可以将其更改为分组为IB或通过代码。默认情况下,表格只设置为单个。 – 2012-04-17 13:34:34

+0

我通过IB更改了它。 – Erakk 2012-04-17 13:42:38