简体   繁体   中英

does reload tabledata affect cellForRowAtIndexPath

I am currently trying to set up my tableview, when its first loaded I call my connection class which in turn calls my parser class then inside my parser class I call a method in my ViewController, which is the original view that is being set up. This method is passed an array which will be used latter.

The method passes the array to an array variable in this ViewController, in this method I then call

[self.tableView reloadData];

and what I am wanting that to do is reload cellForRowAtIndexPath so that it will go through my logic (if statements) and check if ([returnedArray count] != 0){ then do its thing.. but the thread never makes it back to this delegate method, which in turn never makes it back to the if statment.

MORE INFO :)

So first of all, when the the ViewController loads

tableView:cellForRowAtIndexPath: is called and sets up my UITableView that all looks perfect, it then calls my NSURLConnection method which connects to my server downloads all of the data and then passes that over to my parser class. From there my parser dose its thing, and everything is fine.

This is what the code looks like in my tableView:cellForRowAtIndexPath:, method

//..
 if (indexPath.row == 0){            
            if ([FilterArray count] == 0){
                [cellActivityIndicator startAnimating];
                //-- Start NSURLConnection
                EngineRequests *engineRequests = [[EngineRequests alloc] init];
                [engineRequests initalizePacketVariables];
            }
if ([FilterArray count] != 0){
                [cellActivityIndicator stopAnimating];
                cell.accessoryView = nil; //hides activity indicator

                cell.userInteractionEnabled = YES;
                cell.backgroundColor = [UIColor whiteColor];

                UILabel *label1;
                label1 = (UILabel *)[cell viewWithTag:1];
                label1.textColor = [UIColor darkGrayColor];

                UILabel *label2;
                label2 = (UILabel *)[cell viewWithTag:2];
                label2.textColor = [UIColor darkGrayColor];
//...etc

Inside my parser class's parserDidEndDocument method I am passing the NSArray back to the MainView.

- (void)parserDidEndDocument:(NSXMLParser *)parser
{
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@",@"ISCHECKED",@"T"];
    NSArray *filteredArray = [parsedDataArrayOfDictionaries filteredArrayUsingPredicate:predicate];

//call method in VieController1 to pass array over
    SearchViewController *searchViewController = [[SearchViewController alloc] init];
    [SearchViewController initFilterArray:filteredArray];


}

So then I head back over to my VC1 and the method that I have declared in the .h and then obviously in the .m file

and this is all of the code that I have in it.

#pragma - Reciver methods
-(void)initFilterArray:(NSArray*)array
{
    //initalise array variable for use in latter views
    FilterArray = array;

    //reload to make cell white
    [self.tableView reloadData];

//    NSLog(@"%@", FilterArray);
}

While debugging the code the thread makes it to this method and runs everything.. if I uncomment that NSLog, it displays my filitered array and everything. However for some reason the reloadData dose not seem to call tableView:cellForRowAtIndexPath:.. I know this because I have debugged it with breakpoints etc.

So... hopefully this added information will help you help me :)

[self.tableView reloadData];

it will call the delegate methods. if it isn't, you can check if self.tableView is linked to the tableView you want to reload.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM