2012-03-20 5 views
0

これは誘い込むIOS tableviewsとJSONアレイ

のための私を不可解されてきた私は正常に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]; 


} 

EDIT

ある値

@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

2つのこと:デザイナで

は、あなたのテーブルビューにIBOutlet介して接続されていますか?この参照は、コードが指示を送信できるようにするために必要です。

第2に、[tableview reloadData]をどこにでも呼び出すことはできません。データの収集が完了したら、それを呼び出す必要があります。

+0

これはおかげで、私はテーブルビューのアウトレットをデリゲートとデータソースに接続しました。私はreloaddataを持っていませんでしたが、今行う。私は今、インスタンスの変数をテーブルを隠すためにtableViewのローカル宣言を取得しています。私はIBOutlet UITableView * tableViewを持っています。 .h – Herb

+0

IBOutletに別の名前を付けるだけです。 –

+0

もう一度おねがいします。これは私には新しく、私はIBOutletに.mと.hという別の名前を付けましたが、同じものです。たぶん、上の.hを素早く見て、ちょうど投稿して、それが大丈夫かどうか教えてください。 – Herb