我有點難住,出於某種原因,下面的代碼會導致我的應用在真實的iPhone上崩潰,雖然它在模擬器中運行良好,但它抓取一些json並將其放入列表視圖中,是否有人任何想法爲什麼它不斷崩潰?任何幫助是極大的讚賞!iPhone應用程序不斷崩潰?
-------- SecondViewController.m ------
#import "SecondViewController.h"
@interface SecondViewController()
@end
@implementation SecondViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[self fetchPrices];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)fetchPrices
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSData* data = [NSData dataWithContentsOfURL:
[NSURL URLWithString: @"http://url.php"]];
NSError* error;
prices = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
});
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return prices.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PriceCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *price = [prices objectAtIndex:indexPath.row];
NSString *text = [price objectForKey:@"name"];
NSString *name = [price objectForKey:@"price"];
cell.textLabel.text = text;
cell.detailTextLabel.text = [NSString stringWithFormat:@"Price: %@", name];
return cell;
}
@end
----- SecondViewController.h ----
#import <UIKit/UIKit.h>
@interface SecondViewController : UITableViewController {
NSArray *prices;
}
- (void)fetchPrices;
@end
--- - 崩潰日誌---- http://pastebin.com/cnf6L7Jf
你有什麼異常?哪條線路崩潰? –
是的,我們需要崩潰日誌。 – tarmes
@PhillipMills我將崩潰日誌添加到pastbin! –