2010-06-30 6 views
1

데이터를 다시로드하거나 새로 고치려면 UITableViewController를 가져 오는 데 문제가 있습니다.UITableViewController가 데이터를 다시로드하지 않습니다. - ASIHTTPRequest

ASIHTTPRequest를 사용하여 URL을 호출하고 일부 문자열 데이터를 가져 오는 메소드가 있습니다. 이 데이터를 테이블의 셀에 넣으려고하지만 [self.tableview reloadData]가 작동하지 않습니다.

은 내가 ASIHTTPRequest는 별도의 스레드에서의 작업을 완료 할 것으로 생각하고 있었다, 그래서 나는 시도 :

[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 

하는 것도 아무것도하지 않았다한다.

어떻게 데이터를 다시로드 할 수 있습니까? 나는 얼마 동안이 일에 매달 렸습니다.

코드 : MainViewController.h

#import <UIKit/UIKit.h> 
@class ProductClass; 
@interface MainViewController : UITableViewController { 
ProductClass *item; 
} 
@property (nonatomic, retain) ProductClass *item; 
@end 

MainViewController.m

#import "MainViewController.h" 
#import "ASIHTTPRequest.h" 
#import "ProductClass.h" 

@implementation MainViewController 
@synthesize item; 

- (void) viewDidLoad { 
self.title = @"TableView Test"; 
self.tableView.allowsSelection = NO; 
self.item = [[ProductClass alloc] init]; 
    [self callURL]; 
} 

-(void)callURL { 
    NSURL *url = [NSURL URLWithString:@"http://urlgoeshere.com"]; 
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; 
[request setDelegate:self]; 
[request startAsynchronous]; 
} 


- (void)requestFinished:(ASIHTTPRequest *)request { 
//Grab the response 
NSString *responseString = [request responseString]; 
     //Put the result into the ProductClass item 
item.titleOfProduct = responseString; 

    //This line shows that self.tableview does NOT have an address of 0x0 
NSLog(@"%@\n", self.tableView); 

    //Problem line!!!!!! 
    [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 
    //The below lines also do nothing!!!! 
//[self.tableView reloadData]; 
//[[self tableView] reloadData]; 
} 

누구나 어떤 아이디어가 ??? 나는 총 손실에 처해있다.

건배, 브렛

답변

0

당신은 performSelectorOnMainThread 필요하지 않습니다 - asihttprequest 항상 주 스레드에서 선택기를 호출합니다.

테이블에 대한 데이터 소스를 설정 했습니까? 당신은 필드 데이터 소스의 적어도 일부는, 참조 설정해야합니다

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITableViewDatasource_Protocol/Reference/Reference.html

적어도 cellForRowAtIndexPath 및 numberOfRowsInSection을. 여기에 도움이 될 수있는 자습서가 있습니다.

http://icodeblog.com/2008/08/08/iphone-programming-tutorial-populating-uitableview-with-an-nsarray/

관련 문제