ベースのアプリケーションがあり、別のものを単一storyboard
の にロードしたいのですが、これをアプリに実装する方法がわかりません...NSArray
UITableView
現時点で、私のアプリの構造は次のようになります。
タブ バー コントローラー -> ナビゲーション コントローラー - 追加 -> オークション ビュー コントローラーを追加 ([次へ] ボタンでオークション名を追加するための 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を学んでいるので、コードに関するアドバイスや助けをいただければ幸いです。ありがとうございました!