简体   繁体   English

是否重新加载表数据会影响cellForRowAtIndexPath

[英]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. 我当前正在尝试设置表视图,当它第一次加载时,我调用连接类,该类依次调用我的解析器类,然后在我的解析器类内部,我在ViewController中调用了一个方法,该方法是要设置的原始视图。 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 该方法将数组传递给此ViewController中的数组变量,然后在此方法中我调用

[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. 我想做的是重新加载cellForRowAtIndexPath,以便它将通过我的逻辑(if语句)并检查if ([returnedArray count] != 0){然后做它的事情..但是线程永远不会使它回到此委托方法,它再也不会使其返回到if语句。

MORE INFO :) 更多信息 :)

So first of all, when the the ViewController loads 所以首先,当ViewController加载时

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. tableView:cellForRowAtIndexPath:被调用并设置我的UITableView看起来都很完美,然后它调用我的NSURLConnection方法,该方法连接到服务器下载所有数据,然后将其传递给解析器类。 From there my parser dose its thing, and everything is fine. 从那里我的解析器开始处理它的事情,一切都很好。

This is what the code looks like in my tableView:cellForRowAtIndexPath:, method 这就是我的tableView:cellForRowAtIndexPath:方法中的代码

//..
 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. 在解析器类的parserDidEndDocument方法内部,我将NSArray传递回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 因此,我回到了VC1和在.h中声明的方法,然后在.m文件中声明了方法

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. 在调试代码时,线程使之进入该方法并运行所有方法..如果我取消对NSLog的注释,它将显示我的过滤数组和所有内容。 However for some reason the reloadData dose not seem to call tableView:cellForRowAtIndexPath:.. I know this because I have debugged it with breakpoints etc. 但是由于某种原因,reloadData似乎没有调用tableView:cellForRowAtIndexPath:。我知道这是因为我已经用断点等对其进行了调试。

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. 如果不是,则可以检查self.tableView是否链接到要重新加载的tableView。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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