I have an tableview inside a view because I have a uipicker at the bottom of the screen. Now I want to change the first row inside the tableview influenced by uipicker. So I need a static first row and the other rows should be dynamic.
In the first row is a label and a button.
Is that possible?
my code:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [_pickerValues count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [_pickerValues objectAtIndex:row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
//What should I do to get the first row label without remove uibutton inside
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return 1 + 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"DynamicCell";
if ([indexPath row] == 0) {
CellIdentifier = @"StaticCell";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (indexPath.row > 0) {
UILabel *value = (UILabel*)[cell viewWithTag:0];
//...
}
return cell;
}
Thx 4 help.
Yes, this is perfectly acceptable and you look to be doing it correctly.
However, when your picker value changes, you should call reloadData on your tableView so it knows to pick up the new value of the StaticCell.