0

私は奇妙な問題を抱えていて、解決策(または同様のもの)を見つけることができませんでした。問題は、私のUITableViewに初期情報(テスト用)が入力されますが、何をしてもグループ化されたスタイルにできないようです(UIで選択できますが、表示されません)

最初にTabBarプロジェクトを開始し、タブに3番目の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`sOwnerに設定しました。

- (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;
}
4

2 に答える 2

1

As you have modified the - (id)initWithStyle:(UITableViewStyle)style initializer to return a UITableView with a grouped style, do you call this initializer when you initialize the RootViewController?

RootViewController *rvc = [[RootViewController] alloc] initWithStyle: UITableViewStyleGrouped];
于 2012-04-17T12:50:30.427 に答える
1

Grouped tables respond to the sections. You only have 1 section listed so you will only see the 1 group. Try and add a 2nd tableData for the 2nd group and return 2 sections. You will also have to split the data in your -cellForRowAtIndexPath by section as well to make sure the data goes to the right section.

if (indexpath.section == 0) {
   // first section and first tableData
}
if (indexpath.section == 1) {
   // second section and second tableData
}
于 2012-04-17T12:56:03.147 に答える