我在 View 中有一个 TableView ,因为我在屏幕底部有一个 uipicker。现在我想更改受 uipicker 影响的 TableView 中的第一行。所以我需要一个静态的第一行,其他行应该是动态的。
第一行是一个标签和一个按钮。
这可能吗?
我的代码:
- (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;
}
谢谢 4 的帮助。
最佳答案
是的,这是完全可以接受的,而且您看起来做得很好。
但是,当您的选择器值发生变化时,您应该在 tableView 上调用 reloadData,以便它知道选择 StaticCell 的新值。
关于ios - UIView 内部的 UITableView 与第一个单元格静态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9829853/