저는 UITableView를 가지고 있으며 데이터는 외부에 저장된 데이터베이스에서 가져옵니다. 분명히 그 데이터를 가져 오는 데는 시간이 걸리고, 앱이 실행될 때 테이블에 사용되는 데이터가 배열에 없습니다.iOS uitableview 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];
}