我是编程新手。我对继承有一个基本的怀疑。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;
}
选择器.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"];
}