kin*_*ton 1 scroll objective-c uitableview
我正在表视图中加载JSON数据.问题是,如果我滚动表视图,我的应用程序崩溃.以下是代码:
- (void)viewDidLoad {
[super viewDidLoad];
jsonurl=[NSURL URLWithString:@"http://www.1040communications.net/sheeba/stepheni/iphone/stephen.json"];
jsonData=[[NSString alloc]initWithContentsOfURL:jsonurl];
jsonArray = [jsonData JSONValue];
items = [jsonArray objectForKey:@"items"];
story = [NSMutableArray array];
description1 = [NSMutableArray array];
media1 = [NSMutableArray array];
for (NSDictionary *item in items )
{
[story addObject:[item objectForKey:@"title"]];
[media1 addObject:[item objectForKey:@"media"]];
}
NSLog(@"booom:%@",story);
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [story 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:UITableViewStyleGrouped reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text=[story objectAtIndex:indexPath.row];
cell.detailTextLabel.text=[media1 objectAtIndex:indexPath.row];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
您必须保留数组,因为您将它们分配给实例变量:
story = [[NSMutableArray array] retain];
description1 = [[NSMutableArray array] retain];
media1 = [[NSMutableArray array] retain];
Run Code Online (Sandbox Code Playgroud)
如果您在以下情况下需要它们,您还必须保留这些实例变量viewDidLoad:
jsonurl
jsonArray
items
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
384 次 |
| 最近记录: |