- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//NSLog(@"Array: %@",rows);
return [rows count];// AT THIS LINE
}
Programme signal reçu: « EXC_BAD_ACCESS »uitableview Donner erreur
MERCI POUR REPONDRE En fait, je l'ai attaché à la WebPage par NSURL où j'ai fait un tableau PHP et j'ai créé un NSLog où je Je reçois les valeurs dans le tableau, mais quand il excute la ligne retour [nombre de lignes] ;. Il donne une erreur lorsque j'écris statiquement return 2;
puis il s'exécute. Je vous explique ce que je fais. J'INITIALISATION le BNR avec
Name tableViewController=[[JsonTestViewController alloc] initWithNibName:@"JsonTestViewController" bundle:nil];
En JsonTestViewController.m
J'ai ce code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//NSLog(@"Array: %@",rows);
return [rows count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
NSDictionary *dict = [rows objectAtIndex: indexPath.row];
NSString *strlb1=[dict objectForKey:@"block"];
NSString *strlb2=[dict objectForKey:@"name"];
strlb1=[strlb1 stringByAppendingString:@" , "];
strlb1=[strlb1 stringByAppendingString:strlb2];
NSString *[email protected]"FPS : ";
NSString *str2=[dict objectForKey:@"p_hours"];
NSString *strpinf;
if([str2 isEqualToString:@"FP"])
{
[email protected]"Free Parking";
}
else if([str2 isEqualToString:@"12"])
{
[email protected]"2 hours";
}
else if([str2 isEqualToString:@"14"])
{
[email protected]"4 hours";
}
else if([str2 isEqualToString:@"MP"])
{
[email protected]"Metered Parking";
}
str1=[str1 stringByAppendingString:strpinf];
cell.textLabel.text =strlb1;
cell.detailTextLabel.text = str1;
return cell;
}
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"SITE URL"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
if (dict)
{
rows = [dict objectForKey:@"users"];
}
NSLog(@"Array: %@",rows);
[jsonreturn release];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
Pouvez-vous s'il vous plaît poster le code où les lignes sont créées? Il semble que vous ne conserviez pas les lignes, et au moment où -tableView: numberOfRowsInSection: est appelé, les lignes ont été auto-libérées. –
J'ai posté le code – IPhoneCrazy