2011-07-30 3 views
1

[self.tableview reloaddata] 전에 viewDidLoad() 함수에서 데이터로드 옵션을 추가하려고합니다. 추가하는 방법을 잘 모르겠습니다. 사용자에게 데이터로드가 있음을 알리는 방법이 있습니다. JSON 파일을 파싱하는 중입니다. 데이터가 3G에서 매우 느리게로드되므로 데이터를로드하는 옵션이로드된다는 것을 사용자가 알 수있는 더 좋은 방법입니다. 난 당신이 "로드 뷰"가 무슨 뜻인지 확실히 모르겠어요Loading tableview 데이터를 다시로드하기 전에 Loading View를 추가하는 방법이 있습니까?

- (void)viewDidLoad { 
    [super viewDidLoad]; 


// Add the view controller's view to the window and display. 
responseData = [[NSMutableData data] retain]; 
self.twitterArray = [NSMutableArray array]; 
NSURLRequest *request = [NSURLRequest requestWithURL: 
[NSURL URLWithString:@"http://search.twitter.com/search.json?q=mobtuts&rpp=5"]]; 


[[NSURLConnection alloc] initWithRequest:request delegate:self]; 

[super viewWillAppear:animated]; 
} 


- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { 
    [responseData setLength:0]; 
} 

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { 
    [responseData appendData:data]; 
} 


- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
    [connection release]; 

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
    [responseData release]; 

    NSDictionary *results = [responseString JSONValue]; 

    self.twitterArray = [results objectForKey:@"results"]; 

    [self.tableView reloadData]; // How to add loading view before this statement 

} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 

    return [self.twitterArray count]; 
} 

답변

1

하지만 난 당신이 데이터를로드하는 동안 제시해야하는지 활동 표시 또는 뭔가 다른 의미 같아요 여기 내 코드입니다.

  1. 는 가 myLoadingView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; myLoadingView.hidesWhenStopped = YES; [myLoadingView stopAnimating]; [self.view addSubView:myLoadingView];
  2. 당신이 당신의 연결 [myLoadingView startAnimating]를 시작하기 전에보기를 표시의 viewDidLoad에 초기화 바르 UIActivityIndicatorView *myLoadingView;
  3. 을;
  4. 위임 메서드 connectionDidFinishLoading에서 다운로드를 중지하여 다운로드가 다시 숨겨지면 숨 깁니다. after [self.tableView reloadData]; viewDidUnload [myLoadingView release];에서 [myLoadingView stopAnimating];
  5. 릴리스를

당신은 질문이 있으면 물어 주시기 바랍니다 또는 내가 당신을 오해 한 경우.