2012-01-16 5 views
2

저는 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]; 
} 

답변

0

아, 처음에는 행을 선택하는 것과 관련이 있습니다. 제거 [self.tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0 animated:NO scrollPosition:UITableViewScrollPositionMiddle];는 모두 지워까지

1

u는 이미 IB

messageTableView =[[UITableView alloc] init]; 
에서 연결을 완료 한 경우 다음 줄을 타고
관련 문제