2012-01-16 113 views
2

我有一个UITableView和数据从外部存储的数据库中拉出。显然,获取数据需要一些时间,当应用程序启动时,表中没有数据中的表使用它的数据。iOS的uitableview重新加载数据不太工作

当从外部来源加载数据时,我打电话给[self.tableview reloadData];但有一个小问题。第一个单元格在重绘之前没有任何文本,通过选择它或将它从屏幕上滚动出来。我尝试添加电话[self.tableView setNeedsLayout];[self.tableView setNeedsDisplay],但这没有明显的影响。

该数组包含重新加载表时的正确数据,所以它不是竞争条件的事情(我相信!)。

有关可能导致此问题的其他想法?

@implementation EXPMasterViewController 

@synthesize detailViewController = _detailViewController; 
@synthesize partiesModel = _partiesModel; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     self.title = NSLocalizedString(@"Master", @"Master"); 
     self.clearsSelectionOnViewWillAppear = NO; 
     self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0); 

     self.partiesModel = [[Parties alloc] init]; 
     [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(reloadData) 
               name:@"ReloadData" 
               object:nil]; 
    } 
    return self; 
} 

-(void)reloadData{ 
    [self.tableView reloadData]; 
    [self.tableView setNeedsLayout]; 
    [self.tableView setNeedsDisplay]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
    [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0 animated:NO scrollPosition:UITableViewScrollPositionMiddle]; 
} 

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

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    if(self.partiesModel.partiesArray) return [self.partiesModel.partiesArray count]; 
    else return 1; 
} 

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

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

    // Configure the cell. 
    cell.textLabel.text = [[self.partiesModel.partiesArray objectAtIndex:indexPath.row] name]; 
    return cell; 
} 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if (!self.detailViewController) { 
     self.detailViewController = [[[EXPDetailViewController alloc] initWithNibName:@"EXPDetailViewController" bundle:nil] autorelease]; 
    } 
    self.detailViewController.detailItem = [self.partiesModel.partiesArray objectAtIndex: indexPath.row]; 
} 

回答

0

啊修正了它,这是与最初选择一行有关。删除[self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0 animated:NO scrollPosition:UITableViewScrollPositionMiddle];清理这一切

1

取出以下行如果u已经完成了在IB

messageTableView =[[UITableView alloc] init]; 
连接