2012-01-16 8 views
2

私はUITableViewを持っており、データは外部に格納されたデータベースから取得されています。明らかに、そのデータを取得するには時間がかかります。アプリが起動されたときに、そのテーブルがそのデータ用に使用する配列にはデータがありません。iOS uitableview reloadDataはあまり動作していません

データが外部ソースからロードされたときに私は[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]; 
で接続を行っている場合は、以下の行を取り出し
関連する問題