I am not able to figure out what is causing the application crash. A UITableView is being filled with data using the method numberOfRowsInSection. The first two record loads correctly but when the 3rd row is about to load, the app crashes. Please help.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
myDictionary = self.myArray;
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [myDictionary count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"TransHistoryCell";
TransHistoryCell *cell = (TransHistoryCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
#try
{
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"TransHistoryCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
NSDictionary *currentDictionary = [myDictionary objectAtIndex:indexPath.row];
for(NSDictionary *object in currentDictionary)
{
NSString *key = [object valueForKey:#"Key"];
NSString *value = [object valueForKey:#"Value"];
if([key isEqualToString:DATE])
{
cell.dateLabel.text = value;
}
else if([key isEqualToString:TRANSACTION_ID])
{
cell.transactionIdLabel.text = value;
}
else if([key isEqualToString:THIRD_PARTY])
{
cell.thirdPartyLabel.text = value;
}
else if([key isEqualToString:AMOUNT])
{
cell.amountLabel.text = value;
}
else if([key isEqualToString:TRANSACTION_DESC])
{
cell.transactionDescLabel.text = value;
}
}
}
#catch (NSException *exception)
{
NSLog(#"Exception: %#", exception);
}
#finally
{
return cell;
}
}
Exception:
2015-01-14 09:49:12.808 MobileProject[19580:5974561] -[NSNull length]: unrecognized selector sent to instance 0x103796ce0
2015-01-14 09:49:12.812 MobileProject
[19580:5974561] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull length]: unrecognized selector sent to instance 0x103796ce0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001034edf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000102187bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001034f504d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010344d27c ___forwarding___ + 988
4 CoreFoundation 0x000000010344ce18 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001009b2f45 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 65
6 UIKit 0x00000001009b2da0 -[UILabel textRectForBounds:limitedToNumberOfLines:] + 76
7 UIKit 0x00000001009b6852 -[UILabel _intrinsicSizeWithinSize:] + 170
8 UIKit 0x00000001009b6932 -[UILabel intrinsicContentSize] + 76
9 UIKit 0x0000000100e6cea4 -[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 33
10 UIKit 0x0000000100e6cc64 -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 422
11 UIKit 0x0000000100e740d6 -[UIView(AdditionalLayoutSupport) updateConstraints] + 163
12 UIKit 0x00000001009b679d -[UILabel updateConstraints] + 272
13 UIKit 0x0000000100e736fa -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 248
14 UIKit 0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
15 CoreFoundation 0x00000001033f6194 CFArrayApplyFunction + 68
16 UIKit 0x0000000100e7369b -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153
17 Foundation 0x0000000101aead6e -[NSISEngine withBehaviors:performModifications:] + 155
18 UIKit 0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
19 CoreFoundation 0x00000001033f6194 CFArrayApplyFunction + 68
20 UIKit 0x0000000100e7369b -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153
21 UIKit 0x0000000100e738f2 -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
22 UIKit 0x0000000100e73dbe __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 96
23 UIKit 0x0000000100e73a86 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 231
24 UIKit 0x0000000100c698b8 -[UITableViewCellContentView updateConstraintsIfNeeded] + 95
25 UIKit 0x0000000100e7419e -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 159
26 UIKit 0x000000010085ab2d -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 114
27 UIKit 0x0000000100866973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
28 QuartzCore 0x0000000103d6ade8 -[CALayer layoutSublayers] + 150
29 QuartzCore 0x0000000103d5fa0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
30 QuartzCore 0x0000000103d5f87e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
31 QuartzCore 0x0000000103ccd63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
32 QuartzCore 0x0000000103cce74a _ZN2CA11Transaction6commitEv + 390
33 QuartzCore 0x0000000103ccedb5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
34 CoreFoundation 0x0000000103422dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
35 CoreFoundation 0x0000000103422d20 __CFRunLoopDoObservers + 368
36 CoreFoundation 0x0000000103418b53 __CFRunLoopRun + 1123
37 CoreFoundation 0x0000000103418486 CFRunLoopRunSpecific + 470
38 GraphicsServices 0x000000010338b9f0 GSEventRunModal + 161
39 UIKit 0x00000001007ed420 UIApplicationMain + 1282
40 MobileProject 0x0000000100535c83 main + 115
41 libdyld.dylib 0x0000000107323145 start + 1
42 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
you are trying to get the length of what you think is an NSString but is actually NSNull. so check the NSNULL value in both key's ` Key and value
Related
I am trying to populate a table view with the file names of the files located in the documents directory but when the button is clicked to show the table view the app crashes saying that the object at index is 0. but there are 14 objects in the array. What could be the fault?
#implementation loadDataTVC
- (void)viewDidLoad {
[super viewDidLoad];
}
-(void) viewWillAppear:(BOOL)animated{
DataSource *sharedManager = [DataSource sharedManager];
NSString *documentDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
sharedManager.directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentDirectoryPath error:NULL];
NSLog(#"%lu", (unsigned long)[sharedManager.directoryContent count]);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
DataSource *sharedManager = [DataSource sharedManager];
NSString *documentDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
sharedManager.directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentDirectoryPath error:NULL];
if (sharedManager.directoryContent.count > 0) {
return (unsigned long)[sharedManager.directoryContent count];
}
else{
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"files" forIndexPath:indexPath];
DataSource *sharedManager = [DataSource sharedManager];
NSString *documentDirectoryPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0];
sharedManager.directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentDirectoryPath error:NULL];
if (sharedManager.directoryContent.count > 0) {
cell.textLabel.text = [NSString stringWithFormat:#"%#", [sharedManager.directoryContent objectAtIndex:indexPath.row]];
}
else{
cell.textLabel.text = #"No data Available";
}
return cell;
}
The log:
2016-05-18 15:00:44.502 GeoData Grapher[4554:331076] 14
2016-05-18 15:00:47.412 GeoData Grapher[4554:331076] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArray0 objectAtIndex:]: index 0 beyond bounds for empty NSArray'
*** First throw call stack:
(
0 CoreFoundation 0x000000010d2cdd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010cd41deb objc_exception_throw + 48
2 CoreFoundation 0x000000010d275885 -[__NSArray0 objectAtIndex:] + 101
3 GeoData Grapher 0x000000010a5f07d6 -[DeviceListTVC prepareForSegue:sender:] + 326
4 UIKit 0x000000010bcc95d5 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 369
5 UIKit 0x000000010bcc9433 -[UIStoryboardSegueTemplate _perform:] + 82
6 UIKit 0x000000010bcc96f7 -[UIStoryboardSegueTemplate perform:] + 156
7 UIKit 0x000000010b583a8d -[UIApplication sendAction:to:from:forEvent:] + 92
8 UIKit 0x000000010b991067 -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 152
9 UIKit 0x000000010b583a8d -[UIApplication sendAction:to:from:forEvent:] + 92
10 UIKit 0x000000010b6f6e67 -[UIControl sendAction:to:forEvent:] + 67
11 UIKit 0x000000010b6f7143 -[UIControl _sendActionsForEvents:withEvent:] + 327
12 UIKit 0x000000010b6f72be -[UIControl _sendActionsForEvents:withEvent:] + 706
13 UIKit 0x000000010b6f6263 -[UIControl touchesEnded:withEvent:] + 601
14 UIKit 0x000000010b5f699f -[UIWindow _sendTouchesForEvent:] + 835
15 UIKit 0x000000010b5f76d4 -[UIWindow sendEvent:] + 865
16 UIKit 0x000000010b5a2dc6 -[UIApplication sendEvent:] + 263
17 UIKit 0x000000010b57c553 _UIApplicationHandleEventQueue + 6660
18 CoreFoundation 0x000000010d1f3301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
19 CoreFoundation 0x000000010d1e922c __CFRunLoopDoSources0 + 556
20 CoreFoundation 0x000000010d1e86e3 __CFRunLoopRun + 867
21 CoreFoundation 0x000000010d1e80f8 CFRunLoopRunSpecific + 488
22 GraphicsServices 0x000000010eb7aad2 GSEventRunModal + 161
23 UIKit 0x000000010b581f09 UIApplicationMain + 171
24 GeoData Grapher 0x000000010a5f405f main + 111
25 libdyld.dylib 0x000000011253c92d start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The Segue:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSIndexPath *selectedPath = [self.tableView indexPathForCell:sender];
AirconsoleDevice *selectedDevice = self.manager.defaultDevice;
if (selectedPath.section == 0) {
selectedDevice = self.currentDevices[selectedPath.row];
}
if ([segue.identifier isEqualToString:#"session_details"]) {
AirconsoleSession *session = [[AirconsoleSession alloc] initWithDevice:selectedDevice];
currentSession = session;
SessionDetailsVC *sdvc = segue.destinationViewController;
sdvc.session = session;
} else {
// we are presenting the Device Details
DeviceDetailsTVC *ddvc = [segue.destinationViewController viewControllers][0];
ddvc.device = selectedDevice;
}
}
The problem is in this line
DeviceDetailsTVC *ddvc = [segue.destinationViewController viewControllers][0];
ddvc.device = selectedDevice;
The destination controller is I assume a Navigation controller. And you are accessing the first controller in the stack.
Check this is actually set up correctly in the Storyboard. Because thats what the line of code expects, but the crash says it cannot find any member in the viewControllers array.
AFAIK it has nothing to do with the table view and 14 items.
Please help me with my school project, currently i suppose to retrieve a set of record from the database and display the record based on their category.
I am new to IOS programming so please help me.
If possible please explain to me what is my mistake and possible solution to solve it.
Sorry to be rude, i need the solution to solve it as soon as possible cause i also need to work on other part of the project.
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
Error Message
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)
I'm trying to run my app however, every time I click on the Profile link my app crashes and I get the below message in my debugging output. See screen shot below. I am running Xcode 5.1.
[UIImageView setFile:]: unrecognized selector sent to instance 0x10b2ebe00
2014-09-23 11:54:33.498 [1295:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setFile:]: unrecognized selector sent to instance 0x10b2ebe00'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102a97495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001027f699e objc_exception_throw + 43
2 CoreFoundation 0x0000000102b2865d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000102a88d8d ___forwarding___ + 973
4 CoreFoundation 0x0000000102a88938 _CF_forwarding_prep_0 + 120
5 Uscout 0x00000001000084c9 -[ProfileViewController updateUserStatus] + 185
6 Uscout 0x0000000100008408 -[ProfileViewController viewWillAppear:] + 88
7 UIKit 0x000000010149cdb5 -[UIViewController _setViewAppearState:isAnimating:] + 422
8 UIKit 0x00000001014bac4d -[UINavigationController _startTransition:fromViewController:toViewController:] + 707
9 UIKit 0x00000001014bb787 -[UINavigationController _startDeferredTransitionIfNeeded:] + 547
10 UIKit 0x00000001014bc238 -[UINavigationController __viewWillLayoutSubviews] + 43
11 UIKit 0x00000001015d6895 -[UILayoutContainerView layoutSubviews] + 202
12 UIKit 0x0000000101403993 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
13 QuartzCore 0x0000000100e9a802 -[CALayer layoutSublayers] + 151
14 QuartzCore 0x0000000100e8f369 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
15 QuartzCore 0x0000000100e8f1ea _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
16 QuartzCore 0x0000000100e02fb8 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 252
17 QuartzCore 0x0000000100e04030 _ZN2CA11Transaction6commitEv + 394
18 UIKit 0x00000001013a2024 _UIApplicationHandleEventQueue + 10914
19 CoreFoundation 0x0000000102a26d21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
20 CoreFoundation 0x0000000102a265f2 __CFRunLoopDoSources0 + 242
21 CoreFoundation 0x0000000102a4246f __CFRunLoopRun + 767
22 CoreFoundation 0x0000000102a41d83 CFRunLoopRunSpecific + 467
23 GraphicsServices 0x0000000102d5bf04 GSEventRunModal + 161
24 UIKit 0x00000001013a3e33 UIApplicationMain + 1010
25 Uscout 0x0000000100007073 main + 115
26 libdyld.dylib 0x0000000105c505fd start + 1
27 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
ProfileViewController.m
#import "ProfileViewController.h"
#interface ProfileViewController ()
#property (weak, nonatomic) IBOutlet PFImageView *profileImageView;
#property (weak, nonatomic) IBOutlet UILabel *userNameLabel;
#property (weak, nonatomic) IBOutlet UILabel *followersNumberLabel;
#property (weak, nonatomic) IBOutlet UILabel *followingNumberLabel;
#end
#implementation ProfileViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self updateUserStatus];
}
- (void)updateUserStatus {
PFUser *user = [PFUser currentUser];
self.profileImageView.file = user[#"profilePicture"];
[self.profileImageView loadInBackground];
self.userNameLabel.text = user.username;
PFQuery *followingQuery = [PFQuery queryWithClassName:#"Activity"];
[followingQuery whereKey:#"fromUser" equalTo:user];
[followingQuery whereKey:#"type" equalTo:#"follow"];
[followingQuery findObjectsInBackgroundWithBlock:^(NSArray *followingActivities, NSError *error) {
if (!error) {
self.followingNumberLabel.text = [[NSNumber numberWithInteger:followingActivities.count] stringValue];
}
}];
PFQuery *followerQuery = [PFQuery queryWithClassName:#"Activity"];
[followerQuery whereKey:#"toUser" equalTo:user];
[followerQuery whereKey:#"type" equalTo:#"follow"];
[followerQuery findObjectsInBackgroundWithBlock:^(NSArray *followerActivities, NSError *error) {
if (!error) {
self.followersNumberLabel.text = [[NSNumber numberWithInteger:followerActivities.count] stringValue];
}
}];
}
- (IBAction)logout:(id)sender {
}
#end
In your ProfileViewController, in the updateUserStatus method, you are calling the method setFile on an object that doesn't know it. Namely: a UIImageView. Make sure that you are using the object you intend to call that method.
UPDATE:
There we go:
self.profileImageView.file = user[#"profilePicture"];
a UIImageView, such has profileImageView, doesn't have a file property, so you can't set it. Double check what's the intended class for setting the file.
I am created a table view in my storyboard using following code.
#import "FastestTapViewController.h"
#interface FastestTapViewController ()
#end
#implementation FastestTapViewController
{
NSMutableArray *recipes;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
recipes = [NSMutableArray arrayWithObjects:#"Egg Benedict", #"Mushroom Risotto", #"Full Breakfast", #"Hamburger", #"Ham and Egg Sandwich", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [recipes count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [recipes objectAtIndex:indexPath.row];
cell.imageView.image = [UIImage imageNamed:#"creme_brelee.jpg"];
return cell;
}
#end
But it kills while scrolling up showing following EXEC_BAD_ACCESS Error
If i initialise my NSMutableArray using add object see below then it works fine
- (void)viewDidLoad
{
[super viewDidLoad];
// Initialize table data
NSMutableArray *recipes = [[NSMutableArray alloc] init];
[recipes addObject:#"Egg Benedict"];
[recipes addObject:#"Mushroom Risotto"];
[recipes addObject:#"Full Breakfast"];
}
Can i know how to fix it?And why it causes such error while scrolling?
EDIT ERROR using second method :
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]'
*** First throw call stack:
(
0 CoreFoundation 0x01c285e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x019ab8b6 objc_exception_throw + 44
2 CoreFoundation 0x01bc94e6 -[__NSArrayM objectAtIndex:] + 246
3 TapGame 0x00002ffc -[FastestTapViewController tableView:cellForRowAtIndexPath:] + 268
4 UIKit 0x0080861f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
5 UIKit 0x008086f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
6 UIKit 0x007ec774 -[UITableView _updateVisibleCellsNow:] + 2378
7 UIKit 0x007ffe95 -[UITableView layoutSubviews] + 213
8 UIKit 0x00784267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
9 libobjc.A.dylib 0x019bd81f -[NSObject performSelector:withObject:] + 70
10 QuartzCore 0x0429a2ea -[CALayer layoutSublayers] + 148
11 QuartzCore 0x0428e0d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
12 QuartzCore 0x0428df40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
13 QuartzCore 0x041f5ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
14 QuartzCore 0x041f6e71 _ZN2CA11Transaction6commitEv + 393
15 QuartzCore 0x042c2aea _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 474
16 QuartzCore 0x042c2f6b _ZN2CA7Display16TimerDisplayLink8callbackEP16__CFRunLoopTimerPv + 123
17 CoreFoundation 0x01be6bd6 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 22
18 CoreFoundation 0x01be65bd __CFRunLoopDoTimer + 1181
19 CoreFoundation 0x01bce628 __CFRunLoopRun + 1816
20 CoreFoundation 0x01bcdac3 CFRunLoopRunSpecific + 467
21 CoreFoundation 0x01bcd8db CFRunLoopRunInMode + 123
22 GraphicsServices 0x0361b9e2 GSEventRunModal + 192
23 GraphicsServices 0x0361b809 GSEventRun + 104
24 UIKit 0x00719d3b UIApplicationMain + 1225
25 TapGame 0x0000a3e2 main + 130
26 libdyld.dylib 0x02167725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Program ended with exit code: 0
If you're initializing your array as
[NSMutableArray arrayWithObjects:#"Egg Benedict", #"Mushroom Risotto", #"Full Breakfast", #"Hamburger", #"Ham and Egg Sandwich", nil];
it's like, you're declaring your array with autorelease.
[[[NSMutableArray alloc] initWithObjects:#"Egg Benedict", #"Mushroom Risotto", #"Full Breakfast", #"Hamburger", #"Ham and Egg Sandwich", nil] autorelease];
you don't know at which point, the array will be released.
So you better stick to your second solution.
or else try with #property way of declaring NSMutablearray.
The NSMutableArray recipes is probably deallocated from memory and you're attempting to use it again.
You need to retain recipes:
recipes = [[NSMutableArray alloc] initWithObjects:#"Egg Benedict", #"Mushroom Risotto", #"Full Breakfast", #"Hamburger", #"Ham and Egg Sandwich", nil];
Using initWithObjects will directly initialize an array, so it won't be autoreleased; you'll need to include [recipes release]; in dealloc.
Also you could use:
return [self.recipes count];
or simply:
[self.recipes count];
each time i try and click on the search bar, the app keeps crashing, below is the code for the UItableview used with the parse.com SDK, is there something i missed on the code. its crashing when the search bar is clicked, before the keyboard gets loaded.
#
NSRangeException', reason: ' -[NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' ** First throw call stack: ( 0 CoreFoundation 0x0000000102cb1795 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000102a14991 objc_exception_throw + 43 2 CoreFoundation
#
this is the view did load method to load search bar
#interface CarTableViewController () <UISearchDisplayDelegate, UISearchBarDelegate>
{
GADBannerView *bannerView_;
}
# property (nonatomic, strong) UISearchBar * searchbar;
# property (nonatomic, strong) UISearchDisplayController *searchcontroller;
# property (nonatomic, strong) NSMutableArray * SearchResults;
#end
#implementation CarTableViewController
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
//search bar
self.searchbar = [[UISearchBar alloc] initWithFrame: CGRectMake (0, 0, self.view.frame.size.width, 44)];
self.tableView.tableHeaderView = self.searchbar;
self.searchcontroller = [[UISearchDisplayController alloc] initWithSearchBar: self.searchbar contentsController: self];
self.searchcontroller.searchResultsDataSource = self;
self.searchcontroller.searchResultsDelegate = self;
self.searchcontroller.delegate = self;
CGPoint offset = CGPointMake(0, self.searchbar.frame.size.height);
self.tableView.contentOffset = offset;
self.searchResults = [NSMutableArray array];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
this is the load for parse
- (id)initWithCoder:(NSCoder *)aCoder
{
self = [super initWithCoder:aCoder];
if (self) {
self.parseClassName = #"movienow";
self.textKey = #"mName";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = NO;
}
return self;
}
//where to search and other
- (void) filterResults: (NSString *)searchTerm{
[self.SearchResults removeAllObjects];
PFQuery * query = [PFQuery queryWithClassName: self.parseClassName]; // table in which you are looking for
[query whereKeyExists: # "mName"]; // column which you are looking for
[query whereKey: # "mName" containsString : searchTerm];
NSArray * results = [query findObjects];
[self.SearchResults addObjectsFromArray: results];
}
- (BOOL) searchDisplayController:(UISearchDisplayController *) controller shouldReloadTableForSearchString: (NSString *) searchstring {
[self filterResults: searchstring];
return YES;
}
- (NSInteger) Tableview: (UITableView *) Tableview numberOfRowsInSection: (NSInteger) section {
if (Tableview == self.tableView) {
return self.objects.count;
} else {
return self.SearchResults.count;
}
}
- (void) callbackLoadObjectsFromParse: (NSArray *)result error:(NSError *) error {
if (!error) {
[self.SearchResults removeAllObjects],
[self.SearchResults addObjectsFromArray: result];
[self.searchDisplayController.searchResultsTableView reloadData];
} else {
NSLog (# "Error:%# %#", error, [error userInfo]);
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *CellIdentifier = #"CarTableCell";
CarTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[CarTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
if (tableView == self.tableView) {
//cell.mName.text = [object objectForKey:#"objectld"];
NSLog(#"%#",[object objectForKey:#"mName"]);
}
else if (tableView == self.searchDisplayController.searchResultsTableView){
PFObject *searchUser = [self.SearchResults objectAtIndex:indexPath.row];
NSLog(#"%#",[searchUser objectForKey:#"mName"]);
}
// Configure the cell...
return cell;
}
crash log
2014-01-23 15:58:23.440 MovieTimeLK2[8442:70b] * Terminating app due to uncaught exception 'NSRangeException', reason: ' -[NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
** First throw call stack:
(
0 CoreFoundation 0x0000000102cb1795 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000102a14991 objc_exception_throw + 43
2 CoreFoundation 0x0000000102c578e5 -[__NSArrayM objectAtIndex:] + 213
3 MovieTimeLK2 0x0000000100005aab -[CarTableViewController tableView:cellForRowAtIndexPath:object:] + 2155
4 MovieTimeLK2 0x0000000100078c7d -[PFQueryTableViewController tableView:cellForRowAtIndexPath:] + 200
5 UIKit 0x0000000101742b8a -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 348
6 UIKit 0x000000010172a836 -[UITableView _updateVisibleCellsNow:] + 2297
7 UIKit 0x000000010173b381 -[UITableView layoutSubviews] + 207
8 UIKit 0x00000001016d2b27 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 354
9 QuartzCore 0x00000001010c7a22 -[CALayer layoutSublayers] + 151
10 QuartzCore 0x00000001010bc589 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 363
11 UIKit 0x00000001016c7470 -[UIView(Hierarchy) layoutBelowIfNeeded] + 521
12 UIKit 0x00000001019a46c3 -[UISearchDisplayControllerContainerView setFrame:] + 113
13 UIKit 0x000000010199de5f -[UISearchDisplayController setActive:animated:] + 9697
14 UIKit 0x00000001019a0576 -[UISearchDisplayController searchBarTextDidBeginEditing:] + 277
15 UIKit 0x00000001018e31b0 -[UISearchBar(UISearchBarStatic) _searchFieldBeginEditing] + 97
16 UIKit 0x00000001016780ae -[UIApplication sendAction:to:from:forEvent:] + 104
17 UIKit 0x0000000101678044 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 17
18 UIKit 0x000000010174c450 -[UIControl _sendActionsForEvents:withEvent:] + 203
19 UIKit 0x0000000101c83594 -[UITextField willAttachFieldEditor:] + 576
20 UIKit 0x00000001017513d7 -[UIFieldEditor becomeFieldEditorForView:] + 725
21 UIKit 0x0000000101c7b2df -[UITextField _becomeFirstResponder] + 143
22 UIKit 0x00000001018e5eb3 -[UISearchBarTextField _becomeFirstResponder] + 92
23 UIKit 0x000000010179fc0c -[UIResponder becomeFirstResponder] + 340
24 UIKit 0x00000001016c6abc -[UIView(Hierarchy) becomeFirstResponder] + 99
25 UIKit 0x0000000101c7ae53 -[UITextField becomeFirstResponder] + 51
26 UIKit 0x000000010198820c -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) setFirstResponderIfNecessary] + 118
27 UIKit 0x0000000101989fc0 -[UITextInteractionAssistant(UITextInteractionAssistant_Internal) oneFingerTap:] + 1768
28 UIKit 0x000000010198050a _UIGestureRecognizerSendActions + 188
29 UIKit 0x000000010197f470 -[UIGestureRecognizer updateGestureWithEvent:buttonEvent:] + 357
30 UIKit 0x0000000101983829 __UIGestureRecognizerUpdate_block_invoke + 53
31 UIKit 0x00000001019837b1 _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 257
32 UIKit 0x000000010197b87d _UIGestureRecognizerUpdate + 93
33 UIKit 0x00000001016ac925 -[UIWindow _sendGesturesForEvent:] + 928
34 UIKit 0x00000001016ad5e5 -[UIWindow sendEvent:] + 910
35 UIKit 0x0000000101686fa2 -[UIApplication sendEvent:] + 211
36 UIKit 0x0000000101674d7f _UIApplicationHandleEventQueue + 9549
37 CoreFoundation 0x0000000102c40ec1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
38 CoreFoundation 0x0000000102c40792 __CFRunLoopDoSources0 + 242
39 CoreFoundation 0x0000000102c5c61f __CFRunLoopRun + 767
40 CoreFoundation 0x0000000102c5bf33 CFRunLoopRunSpecific + 467
41 GraphicsServices 0x00000001049873a0 GSEventRunModal + 161
42 UIKit 0x0000000101677043 UIApplicationMain + 1010
43 MovieTimeLK2 0x0000000100006c33 main + 115
44 libdyld.dylib 0x00000001035e65fd start + 1
45 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
From the crash log posted, it seems that your problem is in PFObject *searchUser = [self.SearchResults objectAtIndex:indexPath.row];
But that would be strange if you already use return self.SearchResults.count; in - (NSInteger) Tableview: (UITableView *) Tableview numberOfRowsInSection: (NSInteger) section
The first thing that comes to my mind is where you call [self.SearchResults removeAllObjects]; in - (void) filterResults: (NSString *)searchTerm , I suggest using the below code:
- (void) filterResults: (NSString *)searchTerm{
PFQuery * query = [PFQuery queryWithClassName: self.parseClassName]; // table in which you are looking for
[query whereKeyExists: # "mName"]; // column which you are looking for
[query whereKey: # "mName" containsString : searchTerm];
NSArray * results = [query findObjects];
self.SearchResults = [results mutableCopy];
}
Update:
Since it crashes with the first typing, then make sure that numberOfRowsInSection returns self.SearchResults.count not self.objects.count, if it does but doesn't return zero, try replacing self.searchResults = [NSMutableArray array]; with self.searchResults = [[NSMutableArray alloc] init]; in your viewDidLoad
Hope it solves your issue.
I think you don't initializate the mutable array change
self.searchResults = [NSMutableArray array];
to
self.searchResults = [NSMutableArray alloc]init];