UITableViewCell 行意外更改其顺序 [英] UITableViewCell rows changing their order unexpectedly

查看:24
本文介绍了UITableViewCell 行意外更改其顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,需要在其中创建扩展表.为此,我正在使用 SKSTableView 并且视图如下

I have a view in which I need to create expanded table. For that purpose I am using SKSTableView and the view is as given below

一旦表被重新加载,行的顺序就会改变,如下所示

As soon as table gets re loaded the order of rows is changing as shown below

这里的标题是行,其余数据是子行.此视图中的标签是固定的,但在右侧,所有字段都是以编程方式创建的.cellForSubRowAtIndexPath 中的代码如下所示

Heading are rows here and rest data are subrows. Labels in this views are fixed but on right hand side all fields are being created programmatically. Code inside cellForSubRowAtIndexPath is shown below

    UITableViewCell *cell = [tableView   dequeueReusableCellWithIdentifier:CellIdentifier];
        if (!cell) {
                cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier];

        // Make cell unselectable
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        CustomTextField* tf;
        UIButton *button = nil;
        UISegmentedControl *segment = nil;
        [cell.textLabel setFont:FONT_OPENSANS_LIGHT(14)];
        [cell.textLabel setTextColor:[UIColor whiteColor]];

        switch (indexPath.section) {
        //all fields area created here example for 1 of the field is
            tf = nameField_ = [self makeTextField:self.name placeholder:@"Sunil Joshi"];
                        [nameField_ setKeyboardType:UIKeyboardTypeDefault];
                        [cell addSubview:nameField_];


        }
       }


 - (CustomTextField *) makeTextField: (NSString*)text  placeholder:     (NSString*)placeholder  {
    CustomTextField *tf = [[CustomTextField alloc] init];
    tf.placeholder = placeholder ;
    tf.text = text;
    tf.font = FONT_OPENSANS_LIGHT(12);
    tf.adjustsFontSizeToFitWidth = YES;
    tf.enabled = NO;
    tf.textColor = [UIColor whiteColor];
    return tf;
}

请帮助我找出这些行更改顺序的问题.

Please help me in finding the issue why these rows are changing their order.

推荐答案

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
  static NSString *CellIdentifier = @"someThingNew";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (!cell) {
                    cell = [[UITableViewCell alloc]init];
}

试试这个.

这篇关于UITableViewCell 行意外更改其顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆