1
나는 객관적인 C에서 처음으로 일하고 있으며, 내가 답을 찾지 못했다는 문제를 보았습니다.코코아 터치 UITableView 데이터
JSON 데이터 세트에서 데이터 세트를로드하고이를 사용하여 UITableViewController 내에 UITableView를 채 웁니다.
처음에는보기가로드 될 때 (viewDidLoad) URL의 JSON 데이터로 배열을 채 웁니다.
다음으로 데이터가 올바르게로드됩니다. numberOfRowsInSection은 올바른 배열에 30 개의 결과가 있음을 보여줍니다.
그러나 아이폰은 전체 세트를 세 번 테이블 뷰에로드합니다. 여기
그 뷰의 제어기로부터 일부 코드 (트위터 일례로 사용되고이고 I 사용 설정하지 실제 데이터)를- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
//results = [[NSMutableArray alloc] init];
[email protected]"public_timeline";
self.tableView.allowsSelection = NO;
NSString *url = [[NSString alloc] init];
url = [[NSString alloc] initWithFormat:@"http://twitter.com/statuses/%s.json",@"public_timeline"];
if ([results count] == 0) {
[self parseJSON:url];
}
}
Here is the parseJSON (actual parse is done with the Cocoa JSON framework
-(void) parseJSON:(NSString *)URL{
NSURL *JSONURL = [NSURL URLWithString:URL];
NSData *responseData = [[NSData alloc] initWithContentsOfURL:JSONURL];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
results = [[NSMutableArray alloc] initWithArray:[responseString JSONValue]];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [results count];
}
셀의 출력
- (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];
// Set up the cell...
}
NSDictionary *cdict = [results objectAtIndex:indexPath.row];
cell.textLabel.text = [cdict valueForKey:@"text"];
return cell;
}
내가하고있는 일이 최선의 방법인지 잘 모르겠다. 누군가가 나를 도울 수 있다면 그것은 위대 할 것이다.
반환 값을 변경? 아니면 테이블이로드되기 전에 브레이크 포인트가 3 번 발생하는 것을 목격하고 있습니까? – Meltemi
3 데이터의 사본이 뷰 셀에 표시됩니다. – lrudor