2013-04-08 83 views
1

我有兩個UITableView與自定義單元格,並面臨奇怪的行爲。幾個UITableView的自定義單元格。不工作滾動

表格會定期更新新記錄。我添加了20條記錄到表#1,而表#2仍然是空的。所有記錄都不適合屏幕顯示,因此表格會滾動顯示。然後,我在表#2中添加一條記錄,並且表#1停止滾動(您只能看到適合屏幕的前幾條記錄)。

重新加載表#1的數據後,問題消失。

當單元格未定製時,我沒有滾動問題。

#import "MyViewController.h" 
#import "MyCell1.h" 

@implementation MyViewController 
@synthesize table1, table2; 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    viewList = [NSMutableArray array]; 
    viewMemory = [NSMutableArray array]; 

    [table1 setDataSource:self]; 
    [table2 setDataSource:self]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
} 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    NSInteger num = 0; 

    if ([tableView tag] == 1980) { 
     num = [viewList count]; 
    } 
    else if ([tableView tag] == 1981) { 
     num = [viewMemory count]; 
    } 

    return num; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    MyCell1 *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
    NSString *someText; 

    if (!cell) { 
     cell = (MyCell1*)[[[NSBundle mainBundle] loadNibNamed:@"Cell1"owner:self options:nil] objectAtIndex:0]; 
    } 

    if ([tableView tag] == 1980) { 
     someText = [viewList objectAtIndex:indexPath.row]; 
    } 
    else if ([tableView tag] == 1981) { 
     someText = [viewMemory objectAtIndex:indexPath.row]; 
    } 

    [[cell value] setText:someText]; 

    return cell; 
} 

- (IBAction)ButtonClick:(UIButton *)sender { 
    if ([sender tag] == 1980) { 
     [viewList addObject:@"0000"]; 
     [[self table1] reloadData]; 
    } 
    else if ([sender tag] == 1981) { 
     [viewMemory addObject:@"1111"]; 
     [[self table2] reloadData]; 
    } 
} 

@end 

回答

0

在另一個網站我被提議使用beginUpdates - endUpdates而不是reloadData更新記錄在tableviews。所有作品。

相關問題