我正在努力做到这一点,以便当我在 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)当表中加载了这些对象时,我怎样才能向目标视图发送关于发送什么对象的消息呢?
提前致谢