2010-05-06 101 views
0

我有一个问题,我似乎无法看到底部。UITableView填充每一个其他发射

在我看来确实加载了代码,我正在创建一个数组并尝试填充表。出于某种原因,它仅在运行应用程序时每隔一段时间填充数据。

我把日志放在viewDidLoad中,它的运行方式和viewWillAppear一样,并输出数组的正确计数。

此外,UITableView特定方法在工作时会被调用,并且在它不起作用时它们不会被调用。我无法弄清楚这个问题的根源。

同样,这种情况恰好发生在50%的时间。 Theres没有动态的数据可能会绊倒或什么。

#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 
+0

在您的失败案例中调用了您的表dataSource方法的NONE吗? (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; – gnasher 2010-05-06 20:23:00

+0

是没有他们。正在被呼叫。 – g00se0ne 2010-05-06 21:24:23

+0

(1)我是否理解正确,viewDidLoad和viewWillAppear每次运行都很好,并且可以很好地填充数组,但是您的表只更新了50%的时间? (2)没有被调用的UITableView方法,它们从哪里调用,代码是什么样的(你可以发布它)? – progrmr 2010-05-06 22:07:26

回答

0

您需要在viewDidLoad中的结束的tableView的reloadData方法的调用。

+0

我试过所有结果都一样。这完全是50/50。 – g00se0ne 2010-05-07 06:04:48

+0

好吧,无论如何你都需要这个代码。这个问题听起来像是一个构建错误,也许其中一个构建文件覆盖了其他构建文件之一。可能你有两个同名的班级或类似的东西?尝试删除生成文件夹,或做一个生成清洁,看看是否有帮助。 – progrmr 2010-05-07 20:06:53