이는 책략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
이 맞습니까?
어레이를 조작 한 후에'[tableView reloadData]'하시겠습니까? –
이 주셔서 감사하지만 지금은 아래 편집에 문제가 발생했습니다 – Herb