UITableView があり、データは外部に保存されたデータベースから取得されます。明らかに、そのデータをフェッチするには時間がかかります。アプリが起動されたときに、テーブルがデータに使用する配列にデータがありません。
データが外部ソースから読み込まれるときに呼び出します[self.tableview reloadData];
が、わずかな問題があります。最初のセルには、選択するか、画面からスクロールして再描画するまで、テキストはありません。[self.tableView setNeedsLayout];
andへの呼び出しを追加しようとしました[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];
}