我想TableView
根据PickerView
视图中的选择填充 a 的内容。我到目前为止的代码是:
- (IBAction)findOwnerButtonPressed:(id)sender
{
findShip.hidden = NO;
shipOwners.hidden = NO;
boatsTableView.hidden = YES;
boatOwners = [NSArray arrayWithObjects:@"Owner1",@"Owner2",@"Owner3", nil];
}
- (IBAction)findShipButtonPressed:(id)sender
{
shipOwners.hidden = YES;
findShip.hidden = YES;
boatsTableView.hidden = NO;
}
PickerView 数据源
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [boatOwners count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return [boatOwners objectAtIndex:row];
}
PickerView 委托
- (void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *boatsFromOwner = [boatOwners objectAtIndex:[shipOwners selectedRowInComponent:0]];
boatsForOwner = [NSMutableArray arrayWithObjects:nil];
if ([boatsFromOwner isEqualToString:@"Owner1"]) {
[self.boatsForOwner addObject:@"Titanic"];
}
NSLog(@"%@",boatsFromOwner);
}
TableView 数据源和委托
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [boatsForOwner count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [boatsForOwner objectAtIndex:indexPath.row];
return cell;
}
这应该是从 a 归还船东公司PickerWheel
,并把他们的船给我。此代码在表中不返回任何内容。当PickerWheel
我选择它时记录'Owner1'。
我如何将对象添加到数组或如何初始化表或如何将PickerWheel
结果与单词进行比较是我的错误吗?