2010-05-06 99 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