0

ベースのアプリケーションがあり、別のものを単一storyboardの にロードしたいのですが、これをアプリに実装する方法がわかりません...NSArrayUITableView

現時点で、私のアプリの構造は次のようになります。

タブ バー コントローラー -> ナビゲーション コントローラー - 追加 -> オークション ビュー コントローラーを追加 ([次へ] ボタンでオークション名を追加するための UITextfield がある場所 -> ロードする TableView コントローラーNSArray.

NSArray最初のユーザーの選択に基づいて、didSelectRowAtIndexPathアプリケーションはNSArray、同じUITableViewController.

私が達成したいことの例:

「車」を選択するNSArrayと、車のリストが読み込まれます - もう一度「車」カテゴリを選択すると、車のブランドNSArrayなどが読み込まれます...

テーブルビュー フローの例

NSArrayすべてのステップで、選択されたすべての選択肢が new に表示されますが、ユーザーの選択を保存したいと思いますUITableView Controller

これまでのところ、オークション名を設定して最初にロードできるアプリケーションを作成できましたNSArray
次のステップを作成し、NSArrayユーザーの選択に基づいて新しいものをロードするのに助けが必要ですUITableView Controller

私のファイル:

SelectClassTableViewController.h

#import <UIKit/UIKit.h>

@interface SelectClassTableViewController : UITableViewController <UITableViewDataSource, UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UITableView *Classes;

@end

SelectClassTableViewController.h

#import "SelectClassTableViewController.h"

@interface SelectClassTableViewController ()
{
    NSArray *ClassesArray;
}

@end

@implementation SelectClassTableViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    ClassesArray = [[NSArray alloc] initWithObjects:@"Cars", @"Motorcycles", @"Boats", @"Planes", @"Other", nil];
    self.Classes.delegate = self;
    self.Classes.dataSource = self;

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Number of sections in TableView
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return ClassesArray.count;
}

// Set name of grouped table view
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    return @"Select Car Type:";
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ClassesCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Sets 
    cell.textLabel.text = [ClassesArray objectAtIndex:indexPath.row];
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.
    /*
     <#DetailViewController#> *detailViewController = [[<#DetailViewController#> alloc] initWithNibName:@"<#Nib name#>" bundle:nil];
     // ...
     // Pass the selected object to the new view controller.
     [self.navigationController pushViewController:detailViewController animated:YES];
     */
}

@end

.

を使用して実行できることはわかっていUITableViewDataSourceますが、このプロトコルをアプリに実装する方法がわかりません。私はまだObjective-Cを学んでいるので、コードに関するアドバイスや助けをいただければ幸いです。ありがとうございました!

4

1 に答える 1

0

ヘッダーファイルにNSStringを作成します。viewDidLoadで、NSStringをに設定し@"Main"ます。でdidSelectRowAtIndexPath、NSStringを表示する配列(配列1、配列2、配列3 ...)に設定し、テーブルを再読み込みします。

cellForRowAtIndexPath、ifステートメントを使用してNSStringの値をチェックすることにより、フォーカスされている配列を検出します。

if ([string isEqualToString: @"Main"]) {

    //show main array

} else if ([string isEqualToString: @"Cars"]) {

    //show cars array...

}
于 2012-11-24T18:22:47.777 に答える