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