How to set Data Model value on Custom TableView UI

2019-07-27 06:07发布

I am new in iOS and I am facing problem regarding to set Data Model on UIlabel

I used like this code to change

In ConnectiondidFinishLoading

 AuditTextBoxarray=[[NSMutableArray alloc] init];
            for(int i=0;i<idarray.count;i++)
            {
                DataModel *model = [DataModel new];
                model.AuditTextBoxString = @"";
                [AuditTextBoxarray addObject:model];
            }

In cellforrowatindexpath

 cell.lblAuditTextBox.text=[NSString stringWithFormat:@"%@",[AuditTextBoxarray objectAtIndex:indexPath.row ]];

On Button Click

   NSString *String=textView1.text;
   DataModel *model = [AuditTextBoxarray objectAtIndex:index];
   model.AuditTextBoxString = String;

But I am not able to set value of data model in tableview:

enter image description here

How can I set Data Model value to uilabel? I am doing something wrong, but what I am not getting.

DataModel.h

@interface DataModel : NSObject
@property(nonatomic, strong)NSString *strSelected;
@property(nonatomic,strong)NSString *TextViewvalue;
@property(nonatomic,strong)NSString *RateViewValue;
@property(nonatomic,strong)NSString *Popupvalue;
@property(nonatomic,strong)NSString *SurveySelected;
@property(nonatomic,strong)NSString *AuditTextBoxString;

DataModule.m

#import "DataModel.h"

@implementation DataModel

@end

I used DataModule to change Button colour and set it on the table view like this

In ConnectionDidFinishLoading

    for (int i =0; i<idarray.count; i++)
    {
        DataModel *model = [DataModel new];
        model.strSelected = @"";
        [arrData addObject:model];

    }

Button Click

sender.backgroundColor = [UIColor redColor];
DataModel *model = [arrData objectAtIndex:sender.tag];
model.strSelected = @"P";

cellforrowatindexoath

 //background color change on button
    DataModel *model = [arrData objectAtIndex:indexPath.row];
    if([model.strSelected isEqualToString:@"P"])
    {
        cell.passbtn.backgroundColor = [UIColor redColor];
    }

Now I am trying to add text on uilabel frok data model.

2条回答
不美不萌又怎样
2楼-- · 2019-07-27 06:41

I just change code from

cell.lblAuditTextBox.text=[NSString stringWithFormat:@"%@",[AuditTextBoxarray objectAtIndex:indexPath.row ]];

To

DataModel *model = [AuditTextBoxarray objectAtIndex:indexPath.row];
cell.lblAuditTextBox.text=model.AuditTextBoxString
查看更多
叛逆
3楼-- · 2019-07-27 06:42

After you update the dataModel in ConnectiondidFinishLoading or On Button Click, Reload the tableview on main thread(if you are in a separate thread) to refresh the data on the View. something like

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableview reloadData];
});
查看更多
登录 后发表回答