Rahul Sharma
Rahul Sharma

Reputation: 950

What the sequence of UITable view Datasource and delegate when we reload data from table?

Hello I'm beginner in iOS In one of my activity I want to reload table data ...then I have applied this code .....

 -(void)buttonpress
{

   for(int i=0;i<buttonarr.count;i++)
   {
       NSString *butt=[NSString stringWithFormat:@"%@",[buttonarr objectAtIndex:i]];

       for(int j=0;j<LabelTag.count;j++)
       {
            NSString *labelbutt=[NSString stringWithFormat:@"%@",[LabelTag objectAtIndex:j]];

            if([butt isEqualToString:labelbutt])
            {
                  NSIndexPath *indexPath1 =[NSIndexPath indexPathForRow:j inSection:0];
                        NSLog(@"indexPath %@",indexPath1);
                        UITableViewCell *mycel=[self->table_AdviseTestDetails cellForRowAtIndexPath:indexPath1];
                        NSLog(@"cell %@",mycel);

                        UILabel *mybutton=(UILabel*)[mycel viewWithTag:100+j];
                        // mybutton.selected=YES;
                        NSLog(@"label %@",mybutton.text);


                        r=r+[mybutton.text floatValue];
                        NSLog(@"r %f",r);


                    }

                }
            }

          range=1;

[table_AdviseTestDetails reloadData];

        netcharges.text=0;
            z1=0;

            NSLog(@"label arr %@",LabelArr);


                   for(int i=0;i<LabelArr.count;i++)
                    {
                        NSString *y= [NSString stringWithFormat:@"%@",[[LabelArr objectAtIndex:i] valueForKey:@"value"]];


                     z1=z1+[y integerValue];


                        netcharges.text=[NSString stringWithFormat:@"%.2f",z1];
                        NSLog(@"net %@",netcharges.text);
                        //balance.text=[NSString stringWithFormat:@"%.2f",z];

                    }
                    netcharges.text=[NSString stringWithFormat:@"%.2f",[netcharges.text floatValue]-r];

                    NSLog(@"net %@",netcharges.text);
                    point.text=[NSString stringWithFormat:@"%.f",(floor([netcharges.text integerValue]/[[[Point_Result objectAtIndex:0]valueForKey:@"Value"] integerValue]))*[[[Point_Result objectAtIndex:0]valueForKey:@"Points"] integerValue]];
                    balance.text=netcharges.text;
                    NSLog(@"net %@",balance.text);


        }

This is my code please ignore all code think is there [table_AdviseTestDetails reloadData]; when we reload table then my controller go in table datasource ... - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section and after this controller come below line of this [table_AdviseTestDetails reloadData]; and after this controller goes in ... - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath I have problem there .....I want when we reload table then first all datasource and delegate of UITableview run and then run other thing..... So IN my above code ....I want fist reload table data use this

    [table_AdviseTestDetails reloadData];

then run all delegate and datasource of table.....

   - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
     - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

and controller come after this below of [table_AdviseTestDetails reloadData]; this line .....how can do this ..please solve this problem ......thank in advance

Upvotes: 3

Views: 1316

Answers (1)

D-eptdeveloper
D-eptdeveloper

Reputation: 2430

these is the general sequence i am not including all the methods just required ones are here

#pragma mark
#pragma mark - Table view data source
1) -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
2) -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
3) -(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
4) -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

#pragma mark
#pragma mark - Table view delegate
1) -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Upvotes: 10

Related Questions