- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//NSLog(@"Array: %@",rows);
return [rows count];// AT THIS LINE
}
程序接收到的信號:「EXC_BAD_ACCESS」的UITableView給錯誤
THANKS FOR其實我把它連接到的網頁通過NSURL我在那裏做了一個PHP數組,我創建了一個NSLog的,我的答覆 我得到的數組形式的值,但當它優於行返回[rows count] ;.當我靜態寫入return 2;
然後執行時,它會發生錯誤。我正在向你解釋我在做什麼。我與
Name tableViewController=[[JsonTestViewController alloc] initWithNibName:@"JsonTestViewController" bundle:nil];
初始化筆尖在JsonTestViewController.m
我有這樣的代碼:
- (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
你可以請發表代碼創建行嗎?它看起來像你沒有保留行,並且在調用-tableView:numberOfRowsInSection:時,行已經被自動釋放。 – 2009-10-13 06:16:56
我已發佈代碼 – IPhoneCrazy 2009-10-14 07:44:01