1

私は XCode 4.2 を使用しており、iPad 5.0 でビルドをテストしています。

XCode で標準のタブ付きアプリケーションを使用してアプリケーションの構築を開始し、最初のタブ内に 2 つの uitableviews を持つコードを追加しました。

コンパイルされますが、テーブル データはビューに読み込まれません。

アプリの delegate.h:

@interface dmbAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong, nonatomic) UITabBarController *tabBarController;

@end

AppDelegate.m:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    UIViewController *viewController1 = [[[dmbFirstViewController alloc] initWithNibName:@"dmbFirstViewController" bundle:nil] autorelease];
    UIViewController *viewController2 = [[[dmbSecondViewController alloc] initWithNibName:@"dmbSecondViewController" bundle:nil] autorelease];
    self.tabBarController = [[[UITabBarController alloc] init] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    NSLog(@"Loading first tab view from app delegate...");
    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];
    return YES;
}

FirstViewController.h:

@interface dmbFirstViewController : UIViewController {

    ReservationsTable *reservationsController;
    WaitlistTable *waitlistController;
    IBOutlet UITableView *reserveTable;
    IBOutlet UITableView *waitlistTable;
}

FirstViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSLog(@"FirstView Controller - View Loading Started");

    [reserveTable setDataSource:reservationsController];
    [waitlistTable setDataSource:waitlistController];

    NSLog(@"FirstView Controller - Loading Table Views..");

    [reserveTable setDelegate:reservationsController];
    [waitlistTable setDelegate:waitlistController];
    reservationsController.view = reservationsController.tableView;
    waitlistController.view = waitlistController.tableView;

    NSLog(@"FirstView Controller - View Loading Finished");
}

どちらのテーブルにも、標準のテーブル メソッドが実装された .h と .m があります。また、最初のビュー nib ファイルに 2 つのテーブルを追加し、それらをファイル所有者にリンクしました。

更新: ReserveTable.h:

    @interface WaitlistTable : UITableViewController <UITableViewDataSource, UITableViewDelegate>{
        NSMutableArray *waitlistitems;
    }

ReserveTable.m:

- (void)viewDidLoad
{
    NSLog(@"View Did Load - Wait List Table");
    waitlistitems = [[NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"6",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",nil] retain];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    NSLog(@"Inside number of section for Wait List table...");
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"Inside numberofRows for Wait List table...");
    // Return the number of rows in the section.
    return [waitlistitems count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Inside cell for row at index path for Wait List table...");
    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 = [NSString stringWithFormat:@"1.%@" ,[waitlistitems objectAtIndex:indexPath.row]];    
    return cell;
}

考え?

4

2 に答える 2

1

これに変更viewDidLoadします:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    reservationsController = [[ReservationsTable alloc] init];
    waitlistController = [[WaitlistTable alloc] init];

    NSLog(@"FirstView Controller - View Loading Started");

    [reserveTable setDataSource:reservationsController];
    [waitlistTable setDataSource:waitlistController];

    NSLog(@"FirstView Controller - Loading Table Views..");

    [reserveTable setDelegate:reservationsController];
    [waitlistTable setDelegate:waitlistController];

    NSLog(@"FirstView Controller - View Loading Finished");
 }

基本的に、初期化することはありませんtableViewControllers(両方の名前だと思います。名前を「WaitlistTableViewController」や「ReservationsTableViewController」などに変更しますが、それは私だけです)。また、「tableView」をに設定します。 「ビュー」は不要です。

または、さらに良いことに、のinitメソッドでそれらを初期化しますdmbFirstViewController

または、次のdmbFirstViewControllerように使用します。

dmbFirstViewController.h:

@interface dmbFirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

    ReservationsTable *reservationsController;
    WaitlistTable *waitlistController;
    IBOutlet UITableView *reserveTable;
    IBOutlet UITableView *waitlistTable;
    NSMutableArray *waitlistitems;
    NSMutableArray *reserveitems;
}

dmbFirstViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    waitlistitems = [[NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"6",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",nil] retain];

    NSLog(@"FirstView Controller - View Loading Started");

    [reserveTable setDataSource:self];
    [waitlistTable setDataSource:self];

    NSLog(@"FirstView Controller - Loading Table Views..");

    [reserveTable setDelegate:self];
    [waitlistTable setDelegate:self];

    NSLog(@"FirstView Controller - View Loading Finished");
}

- (void)viewDidAppear:(BOOL)animated
{
    [reserveTable reloadData];
    [waitlistTable reloadData];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    NSLog(@"Inside number of section for Wait List table...");
    if(tableView == waitlistTable)
    {
        //Return sections for waitlistTable
        return 1;
    }else{
        //Return sections for reservedTable
        return 1;
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(tableView==waitlistTable)
    {
        NSLog(@"Inside numberofRows for Wait List table...");
        // Return the number of rows in waitlistTable section.
        return [waitlistitems count];
    }else{
        // Return the number of rows in reservedTable section.
        return [reserveditems count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if(tableView == waitlistTable)
    { 
        NSLog(@"Inside cell for row at index path for Wait List table...");
        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 = [NSString stringWithFormat:@"1.%@" ,[waitlistitems objectAtIndex:indexPath.row]];    
        return cell;
    } else {
        //Create cell for reservedTable Cell
        .....
        return cell;
    }
}

セルに関する部分を終了する必要がありreservedTableます。私にはそのコードがありませんでした。さらに、items配列を推測し、reservedTable初期化しませんでした。

于 2012-06-25T20:04:50.690 に答える
1

I think in your firstViewController you should push the views. Assuming that reserveTable is your main table, push it like so

[self.view addSubView:reserveTable];

Also, did you import the ReserveTable.h to your firstViewController?

If yes, you should initialize the table there though.

But what i suggest, though, is to transform the firstViewController in a tableViewController, editing the App Delegate and the firstViewController.h and m, and from there initialize the table (even adding the other one too). So that would be easier!

于 2012-06-25T19:58:53.617 に答える