picherWheelで船の所有者を選択すると、彼らのボートがtableViewに表示されるようにしようとしています。現在、私はこのように、ピッカーで if-else シリーズを使用して NSMutableArray をフィードすることでそれを行っています。
-(void)updatePicker
{
NSString *boatsFromOwner = [boatOwners objectAtIndex:[shipOwners selectedRowInComponent:0]];
boatsForOwner = [[NSMutableArray alloc] init];
if ([boatsFromOwner isEqualToString:@"Owner1"]) {
[self.boatsForOwner addObject:@"Titanic1"];
[self.boatsForOwner addObject:@"Titanic2"];
[self.boatsForOwner addObject:@"Titanic3"];
[self.boatsForOwner addObject:@"Titanic4"];
[self.boatsForOwner addObject:@"Titanic5"];
[self.boatsForOwner addObject:@"Titanic6"];
[self.boatsForOwner addObject:@"Titanic7"];
}
if ([boatsFromOwner isEqualToString:@"Owner2"]) {
[self.boatsForOwner addObject:@"Titanic1"];
[self.boatsForOwner addObject:@"Titanic2"];
[self.boatsForOwner addObject:@"Titanic3"];
}
次に、次のように tableView に読み取ります。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [boatsForOwner count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableCell";
SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
cell.nameLabel.text = [boatsForOwner objectAtIndex:indexPath.row];
cell.moreInfoLabel.text = [boatsForOwner objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
UITableViewCell *cell = [self.boatsTableView cellForRowAtIndexPath:indexPath];
[self performSegueWithIdentifier:@"boatInfoSegue" sender:cell];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
これで問題なく動作します。しかし、複数の場所で必要になるため、NSObjects を使用して船に関する情報を保存するのが賢明であると考えました。そこで、次のような船のオブジェクトをいくつか作成しました。
cargoShips* Titanic = [[cargoShips alloc]init];
Titanic.name = @"Titanic1";
Titanic.size = @"1000";
Titanic.owner = @"Owner1";
cargoShips* Titanic2 = [[cargoShips alloc]init];
Titanic2.name = @"Titanic2";
Titanic2.size = @"2000";
Titanic2.owner = @"Owner2";
これは正しくログに記録され、うまく機能します。最初の質問は次のとおりです。
1) pickerWheel のオブジェクトを *.owner にリンクするにはどうすればよいですか? ホイールで「Owner1」を選択すると、タグ付けされたすべてのボートを取得でき*.owner = @"Owner1"
ますか?
2)これらのボートの *.name を UITableView に入力するにはどうすればよいですか?
3)これらのオブジェクトがテーブルにロードされた場合、どのオブジェクトがメッセージを送信したかについて、ターゲット ビューにメッセージを送信するにはどうすればよいでしょうか?
前もって感謝します