這已經莫名其妙我詭計IOS tableviews和JSON陣列
我成功地從填充一個JSON調用數組,但表視圖我想poulate是不會發生的。
任何人都可以看到爲什麼?
我已經嘗試了好幾個事情,但數組獲得通過到的tableView是沒有得到填充成功檢索的JSON值
- (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];
}
編輯
我的.h是
@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]? – 2012-03-20 20:38:23
感謝這,但我現在正在編輯下面的問題 – Herb 2012-03-20 21:26:51