私はプログラミングの初心者です.私は継承の基本的な疑いがあります.私は持っていて、最初の行を選択するとUITableView
.これは私が直面している小さな問題です。ViewController
Tableview
Picker
UIPickerView
NSLOG
picker
ViewController
button
ビューコントローラー.m
- (void)viewDidLoad
{
[super viewDidLoad];
tableview =[[UITableView alloc]initWithFrame:CGRectMake(0,0,([UIScreen mainScreen].bounds.size.width),([UIScreen mainScreen].bounds.size.height/2)) style:UITableViewStyleGrouped];
tableview.delegate=self;
tableview.dataSource=self;
[self.view addSubview:tableview];
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(pressed) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"START " forState:UIControlStateNormal];
button.frame = CGRectMake(62, 250, 196, 37);
[self.view addSubview:button];
thearray= [[NSArray alloc]initWithObjects:@"A",@"B ",@"C",@"D",@"E" ,nil];
[super viewDidUnload];
}
-(void)pressed{
// nslog value..i need here the picker value
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 5;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row==0){
Picker1 *pick= [[Picker1 alloc] init];
[self navigationController] pushViewController:pick animated:YES]
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NS IndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
}
cell.textLabel.text=[thearray objectAtIndex:indexPath.row];
return cell;
}
Picker.m
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [list count];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [list objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// update label text to show selected option
string=[NSString stringWithFormat:@"%@",[list objectAtIndex:row]];
label.text=string;
[self dismissModalViewControllerAnimated:YES];
}
- (void)viewDidLoad
{
[super viewDidLoad];
list =[[NSMutableArray alloc]init];
[list addObject:@"A"];
[list addObject:@"B"];
[list addObject:@"C"];
}