请帮我学校项目,目前我想从数据库中检索一组记录并根据他们的类别显示记录。 我是IOS编程的新手,所以请帮助我。 如果可能的话请向我解释一下我的错误和可能的解决办法。 抱歉粗鲁,我需要解决方案尽快解决,因为我还需要在项目的其他部分工作。
LocationListTableViewController.m
#import "LocationListTableViewController.h"
#import <Parse/Parse.h>
@interface LocationListTableViewController ()
@property (strong, nonatomic) IBOutlet UITableView *testView;
@end
@implementation LocationListTableViewController {
NSArray *storeLocation;
NSMutableDictionary *categoriesDict;
NSString *checkValue;
}
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
PFQuery *query = [PFQuery queryWithClassName:@"GPS"];
// pulling everything
UIActivityIndicatorView *ai = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
ai.center = self.view.center;
[ai startAnimating];
[self.view addSubview:ai];
storeLocation = [query findObjects];
[ai stopAnimating];
[self.tableView reloadData];
categoriesDict = [[NSMutableDictionary alloc]init];
for (NSDictionary *locationCat in storeLocation) {
NSString *stringLocation = [locationCat objectForKey:@"locationCategory"];
NSMutableSet *categoriesSet = [categoriesDict objectForKey:stringLocation];
if (!categoriesSet)
{
categoriesSet = [NSMutableSet set];
[categoriesDict setObject:categoriesSet forKey:[locationCat objectForKey:@"locationCategory"]];
}
[categoriesSet addObject:locationCat];
// NSLog(@"categroesDict value are %d", [[categoriesDict objectForKey:@"All"] count]);
// NSLog(@"categroesDict value are %@", [categoriesDict objectForKey:@"test"]);
};
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[categoriesDict objectForKey:checkValue] count];
}
-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleid = @"Location";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleid];
if (cell == nil)
{
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:simpleid];
}
// NSLog(@"categoriesDict objectForKey:checkValue ---- %@", [categoriesDict objectForKey:checkValue]);
// NSLog(@"categoriesDict objectForKey:checkValue valueForKey ---- %@", [[categoriesDict objectForKey:checkValue]valueForKey:@"locationCategory"]);
// NSLog(@"categoriesDict objectForKey:checkValue valueForKey ---- %@", [[categoriesDict objectForKey:checkValue]valueForKey:@"locationName"]);
UILabel *locationLabel = (UILabel *)[cell viewWithTag:100];
locationLabel.text = [[categoriesDict objectForKey:checkValue]valueForKey:@"locationName"];
UILabel *addressLabel = (UILabel *)[cell viewWithTag:101];
addressLabel.text = [[categoriesDict objectForKey:checkValue]valueForKey:@"locationAddress"];
UIImageView *thumbnailImageView = (PFImageView *)[cell viewWithTag:102];
self.thumbnail= [[categoriesDict objectForKey:checkValue]valueForKey:@"locationImage"];
// NSLog(@"thumbnail is %@", self.thumbnail);
if (self.thumbnail == NULL)
{
thumbnailImageView.image= [UIImage imageNamed:@"placeholder.jpg"];
} else
{
//Got error occurred
[self.thumbnail getDataInBackgroundWithBlock:^(NSData *imageData, NSError *error) {
if (!error) {
UIImage *image = [UIImage imageWithData:imageData];
thumbnailImageView.image = image;
}
else{
NSLog(@"imageData value; %@", imageData);
}
}];
}
return cell;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [categoriesDict count];
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
checkValue = [[categoriesDict allKeys]objectAtIndex:section];
return [[categoriesDict allKeys]objectAtIndex:section];
}
@end
错误消息
2015-01-14 15:27:36.658 MyLocationDemo[5591:60b] Warning: A long-running operation is being executed on the main thread.
Break on warnBlockingOperationOnMainThread() to debug.
2015-01-14 15:28:04.207 MyLocationDemo[5591:60b] -[__NSSetI getDataInBackgroundWithBlock:]: unrecognized selector sent to instance 0xaabed00
2015-01-14 15:28:04.208 MyLocationDemo[5591:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSSetI getDataInBackgroundWithBlock:]: unrecognized selector sent to instance 0xaabed00'
*** First throw call stack:
(
0 CoreFoundation 0x027711e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x024f08e5 objc_exception_throw + 44
2 CoreFoundation 0x0280e243 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0276150b ___forwarding___ + 1019
4 CoreFoundation 0x027610ee _CF_forwarding_prep_0 + 14
5 MyLocationDemo 0x000030df -[LocationListTableViewController tableView:cellForRowAtIndexPath:] + 1199
6 UIKit 0x012a911f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
7 UIKit 0x012a91f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
8 UIKit 0x0128aece -[UITableView _updateVisibleCellsNow:] + 2428
9 UIKit 0x0129f6a5 -[UITableView layoutSubviews] + 213
10 UIKit 0x0121f964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
11 libobjc.A.dylib 0x0250282b -[NSObject performSelector:withObject:] + 70
12 QuartzCore 0x004ee45a -[CALayer layoutSublayers] + 148
13 QuartzCore 0x004e2244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
14 QuartzCore 0x004e20b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
15 QuartzCore 0x004487fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
16 QuartzCore 0x00449b85 _ZN2CA11Transaction6commitEv + 393
17 QuartzCore 0x005075b0 +[CATransaction flush] + 52
18 UIKit 0x011ae9bb _UIApplicationHandleEventQueue + 13095
19 CoreFoundation 0x026fa77f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
20 CoreFoundation 0x026fa10b __CFRunLoopDoSources0 + 235
21 CoreFoundation 0x027171ae __CFRunLoopRun + 910
22 CoreFoundation 0x027169d3 CFRunLoopRunSpecific + 467
23 CoreFoundation 0x027167eb CFRunLoopRunInMode + 123
24 GraphicsServices 0x043555ee GSEventRunModal + 192
25 GraphicsServices 0x0435542b GSEventRun + 104
26 UIKit 0x011b0f9b UIApplicationMain + 1225
27 MyLocationDemo 0x0000391d main + 141
28 libdyld.dylib 0x02cba701 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)