次のチュートリアルに従って問題はありませんでした: http://www.raywenderlich.com/1797/how-to-create-a-simple-iphone-app-tutorial-part-1 . 本質的に、このチュートリアルでは、NSMutableArray からのデータが入力された単純なテーブル ビューを作成し、続いて各アイテムの DetailView にドリルダウンする方法を説明します。
次に、TabViewController を作成し、作成したテーブル ビューをこのコントローラーの「タブ項目 2」として持つことで、自分が持っていたものを強化しようとしました。
これにより、テーブルの自動入力が壊れています。
AppDelegate.mからテーブルを作成するために使用されるコード
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
Person *person1 = [[Person alloc] initWithName:@"Monica"
balance:420
thumbImage:[UIImage imageNamed:@"01.jpg"]
fullImage:[UIImage imageNamed:@"01_t.jpg"]];
Person *person2 = [[Person alloc] initWithName:@"Ross"
balance:630
thumbImage:[UIImage imageNamed:@"02.jpg"]
fullImage:[UIImage imageNamed:@"02_t.jpg"]];
Person *person3 = [[Person alloc] initWithName:@"Rachel"
balance:420
thumbImage:[UIImage imageNamed:@"03.jpg"]
fullImage:[UIImage imageNamed:@"03_t.jpg"]];
NSMutableArray *persons = [NSMutableArray arrayWithObjects:person1, person2, person3, nil];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *initialViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"RootViewController"];
self.window.rootViewController = initialViewController;
TableViewController * peopleTableViewController = [storyboard instantiateViewControllerWithIdentifier:@"PersonTableViewController"];
[peopleTableViewController setPersons: persons];
// Override point for customization after application launch.
return YES;
}
「persons」は、TableViewController のプロパティである Person インスタンスの配列です。以下は、 TableViewController.mの 'persons' 配列に基づくテーブルの母集団です。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PersonCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//For each person
Person *person = [self.persons objectAtIndex:indexPath.row];
cell.textLabel.text = person.name;
cell.imageView.image = person.thumbImage;
cell.detailTextLabel.text = [person getPrice];
return cell;
}
最後に、ストーリーボードは次の場所にあります: http://i.stack.imgur.com/9axs8.png
繰り返しになりますが、これはすべて正常にコンパイルされますが、テスト中にタブ項目 #2 (ストーリーボードに従ってテーブル ビュー コントローラーが存在する場所) を開くとテーブルが空になります。これは、タブを追加する前に機能していました。
私はまだ Objective C に非常に慣れていないので、他に必要な情報があれば教えてください。