【问题标题】:UITableView inside UIView with first cell staticUIView 内的 UITableView 与第一个单元格静态
【发布时间】:2012-03-22 20:19:27
【问题描述】:

我在视图中有一个 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 帮助。

【问题讨论】:

    标签: ios ios5 uitableview uipickerview


    【解决方案1】:

    是的,这是完全可以接受的,而且您看起来做得正确。

    但是,当您的选择器值发生变化时,您应该在您的 tableView 上调用 reloadData,以便它知道获取 StaticCell 的新值。

    【讨论】:

    • 或者 reloadRowsAtIndexPaths:withRowAnimation: 如果你想要动画 =)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多