Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UITableView每隔一次启动填充一次_Iphone_Uitableview - Fatal编程技术网

Iphone UITableView每隔一次启动填充一次

Iphone UITableView每隔一次启动填充一次,iphone,uitableview,Iphone,Uitableview,我有一个问题,我似乎无法弄清到底 在我的视图中,我正在创建一个数组并尝试填充表。出于某种原因,它只会每隔一段时间在应用程序运行时填充数据 我将日志放在viewDidLoad中,它与ViewWillDisplay一样运行,并为数组输出正确的计数 此外,UITableView特定方法在工作时会被调用,而在不工作时不会被调用。我想不出这个问题的根源 同样,这种情况也有50%的时间发生。没有动态数据可能会被绊倒或其他任何东西 #import "InfoViewController.h" @implem

我有一个问题,我似乎无法弄清到底

在我的视图中,我正在创建一个数组并尝试填充表。出于某种原因,它只会每隔一段时间在应用程序运行时填充数据

我将日志放在viewDidLoad中,它与ViewWillDisplay一样运行,并为数组输出正确的计数

此外,UITableView特定方法在工作时会被调用,而在不工作时不会被调用。我想不出这个问题的根源

同样,这种情况也有50%的时间发生。没有动态数据可能会被绊倒或其他任何东西

#import "InfoViewController.h"

@implementation InfoViewController

- (void)viewDidLoad
{
    NSLog(@"Info View Loaded"); // This runs

    infoList = [[NSMutableArray alloc] init];
    //Set The Data //Theres 8 similar lines
    [infoList addObject :[[NSMutableDictionary alloc] initWithObjectsAndKeys: @"Scrubbed", @"name", @"scrubbed", @"url", nil]];

    NSLog(@"%d", [infoList count]); // This shows the count correctly every time

    [super viewDidLoad];
}

-(void) viewWillAppear:(BOOL)animated
{
    NSLog(@"Info Will Appear"); // This Runs
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  // This WILL NOT RUN when it doesnt work, and DOES show the count when it does run
    NSLog(@"Counted in numberOfRowsInSection %d", [infoList count]);
    return [infoList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"ROW");
    static NSString *CellIdentifier = @"infoCell";  

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;   
    cell.textLabel.text = [[infoList objectAtIndex:indexPath.row] objectForKey:@"name"];

    return cell;
}


@end

您需要在viewDidLoad的末尾调用tableView的reloadData方法。

在失败案例中是否没有调用任何表数据源方法?i、 e.-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节;是的,没有。正在调用。(1)我是否理解正确,viewDidLoad和ViewView似乎每次都运行良好,并可以很好地填充数组,但您的表只更新了50%的时间?(2) 未被调用的UITableView方法,它们从何处调用,代码是什么样子的(你能发布它吗)?1)是的,这是正确的。2) 代码已发布。请注意,每隔一次我从XCode构建并运行时都会发生这种情况。。。如果每次我只是点击模拟器上的图标,它似乎都会在最初做的事情上做/或100%。我试过所有结果都是一样的。确切地说是50/50。好吧,无论如何,你确实需要在某个地方使用这些代码。该问题听起来像是生成错误,可能其中一个生成文件正在覆盖另一个生成文件。您可能有两个同名或类似的类?尝试删除生成文件夹,或者进行生成清理,看看是否有帮助。