2012-03-20 5 views
0

이는 책략IOS의 tableviews 및 JSON 배열

내가 성공적으로는 A JSON 통화에서 배열하지만 poulate 할 테이블 뷰가 같이 발생되지 않습니다 채우는하고 나를 이해할 수없는되었습니다.

누구나 볼 수 있습니까?

나는 좋은 몇 가지를 시도했지만 배열이 성공적으로 JSON을 검색으로 채워지고 있지 않은있는 tableView에 전달하기 내 .H는

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; 
    self.responseData = nil; 

    NSArray* categories = [(NSDictionary*)[responseString JSONValue] objectForKey:@"categories"]; 
    [responseString release]; 


    //fetch the data 
    for (NSDictionary* item in categories) {   
     NSString* c = [item objectForKey:@"CATEGORY_NAME"]; 
     [self.tableViewArray addObject:[NSString stringWithFormat:@"%@", c]]; 
    } 

} 

    - (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self loadData]; 
} 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [tableViewArray 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]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    // Configure the cell. 
    NSInteger rowNumber = indexPath.row; 
    NSString *stateName = [tableViewArray objectAtIndex:rowNumber]; 
    cell.textLabel.text = stateName; 
    return cell; 
} 

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSString *message = [NSString stringWithFormat:@"You selected %@",[self.tableViewArray objectAtIndex:indexPath.row]]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message: message delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil]; 

    [alert show]; 

    [alert release]; 


} 

편집

입니다 값

@interface Medical_MeetingsViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { 
    NSMutableArray *tableViewArray; 
    NSMutableData *responseData; 
    IBOutlet UITableView *tableViewCat; 
} 

@property (nonatomic, retain) NSMutableArray *tableViewArray; 
@property (retain, nonatomic) NSMutableData *responseData; 

-(IBAction)loadData; 

@end 

이 맞습니까?

+0

어레이를 조작 한 후에'[tableView reloadData]'하시겠습니까? –

+0

이 주셔서 감사하지만 지금은 아래 편집에 문제가 발생했습니다 – Herb

답변

1

두 가지 : 디자이너에서

, 당신은 당신의 TableView가 함께 IBOutlet을 통해 연결해야합니까? 이 참조는 코드에서 지침을 보낼 수 있도록 필요합니다.

두 번째로 [tableview reloadData]을 어디에서나 호출하는 것을 볼 수 없으므로 데이터 수집을 마친 후에 전화해야합니다.

+0

감사합니다. 덕분에, 나는 tableview의 대리점을 대리인 및 데이터 소스에 연결했습니다. 나는 reloaddata를 가지고 있지 않았지만 지금한다. 지금은 tableView의 로컬 선언이 인스턴스 변수를 숨기고 IBOutlet UITableView * tableView가 있습니다. in .h – Herb

+0

IBOutlet에 다른 이름을 지정하기 만하면됩니다. –

+0

다시 한 번 감사드립니다.이 새로운 것을 알 수 있듯이, IBOutlet에 .m 및 .h라는 다른 이름을 지정했지만 동일한 이름을 사용했습니다. 어쩌면 위의 .h를 방금 전에 올려 놓고 확인해도 될까요? – Herb