这是一个非常广泛的问题,而不是针对单个问题的具体问题。如果您不想帮助其中之一,这里是您的警告!
我有一个带有pickerWheel
. 在这个选择器上,我想要一份 Cargo 船东的名单。当我按下OK
按钮时,我希望UITableView
由该所有者拥有的船填充。不多,大约5艘。我希望与tableView
选择器处于同一视图中。
当我按下列表中的一艘船时,我想被引导到另一个视图,在那里我可以从另一个视图添加可变数字,例如运输负载等。
我知道如何制作和填充以及从选择器中提取数据,我不知道如何使用这些数据以某种方式填充表格,我不知道如何使用表格上的对象将我链接到我所在的视图可以根据发送者设置不同的值。
我不擅长编程,所以带有代码的完整解决方案会很棒!:)
编辑:我到目前为止的代码
.h file
#import <UIKit/UIKit.h>
#import "StartupViewController.h"
@interface CargoViewController : UIViewController
@property(strong,nonatomic) IBOutlet UILabel *testLabel; //label I use to test stuff instead of LOG
@property(strong,nonatomic) IBOutlet UIButton *findOwner; //button to summon pickerWheel
@property(strong,nonatomic) IBOutlet UIButton *findShip; //Button to confirm selection in picker and unhide tableView
@property(strong,nonatomic) NSArray *boatOwners; //Array for boat owners.
@property(strong,nonatomic) NSMutableArray *boatsForOwner; //My idea was that when you select a owner, i have a if-else series, so say i select "Bob", I code to add his boats to the array. Does this work? IDK
@property(strong,nonatomic) IBOutlet UITableView *boatsTableView; //Table view
-(IBAction)findOwnerButtonPressed:(id)sender;
-(IBAction)findShipButtonPressed:(id)sender;
@property(strong, nonatomic) IBOutlet UIPickerView *shipOwners; //ship owner picker wheel
@end
.m 文件:
#import "CargoViewController.h"
@interface CargoViewController ()
@end
@implementation CargoViewController
@synthesize testLabel, findOwner, findShip,shipOwners, boatsTableView;
@synthesize boatsForOwner, boatOwners;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[self getDataFromDensity ];
boatOwners = @[@"owner1", @"owner2", @"owner3"];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void) getDataFromDensity
{
NSString *getData = [[NSUserDefaults standardUserDefaults]
objectForKey:@"globalMathString"]; //Gets a number from another view, wanted to use in the information about boat view later on.
testLabel.text = getData;
[boatsForOwner setValue:@"5" forKey:getData];
}
-(IBAction)findOwnerButtonPressed:(id)sender
{
findShip.hidden = NO;
shipOwners.hidden = NO;
boatsTableView.hidden = YES;
}
-(IBAction)findShipButtonPressed:(id)sender
{
shipOwners.hidden = YES;
findShip.hidden = YES;
boatsTableView.hidden = NO;
}
#pragma mark -
#pragma mark PickerView DataSource
- (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];
}
#pragma mark -
#pragma mark PickerView Delegate
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
NSString *boatsFromOwner = [boatOwners objectAtIndex:[shipOwners selectedRowInComponent:0]];
}