I am attempting to display Instagram Comments in a Detail View Controller. I am pushing the data from a Master View Controller shown below:
MessageViewController *message = [[MessageViewController alloc] init];
NSInteger row = [[self tableView].indexPathForSelectedRow row];
NSDictionary *pic = [instaPics objectAtIndex:row];
message.instagramData = pic;
[self.navigationController pushViewController:message animated:YES];
However when I tap the button to go to the Detail View Controller I get this error:
2015-05-02 01:29:56.464 Floadt[40646:4284271] Successfully commented Picture
2015-05-02 01:29:56.516 Floadt[40646:4284271] -[__NSCFArray objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7fd06be6cc40
2015-05-02 01:29:56.529 Floadt[40646:4284271] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectForKeyedSubscript:]: unrecognized selector sent to instance 0x7fd06be6cc40'
*** First throw call stack:
(
0 CoreFoundation 0x000000010dc5bc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d537bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010dc630ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010dbb913c ___forwarding___ + 988
4 CoreFoundation 0x000000010dbb8cd8 _CF_forwarding_prep_0 + 120
5 Floadt 0x000000010a1104d0 -[MessageViewController messageCellForRowAtIndexPath:] + 256
6 Floadt 0x000000010a11035c -[MessageViewController tableView:cellForRowAtIndexPath:] + 188
7 UIKit 0x000000010c36ca28 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
8 UIKit 0x000000010c34b248 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2853
9 UIKit 0x000000010c3618a9 -[UITableView layoutSubviews] + 210
10 UIKit 0x000000010c2eba2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
11 QuartzCore 0x000000010c0afec2 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x000000010c0a46d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 UIKit 0x000000010c2df675 -[UIView(Hierarchy) layoutBelowIfNeeded] + 607
14 Floadt 0x000000010a0908a8 -[SLKTextViewController viewWillAppear:] + 296
15 UIKit 0x000000010c39ffa1 -[UIViewController _setViewAppearState:isAnimating:] + 487
16 UIKit 0x000000010c3c1395 -[UINavigationController _startCustomTransition:] + 887
17 UIKit 0x000000010c3cd3bf -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
18 UIKit 0x000000010c3cdf0e -[UINavigationController __viewWillLayoutSubviews] + 43
19 UIKit 0x000000010c518715 -[UILayoutContainerView layoutSubviews] + 202
20 UIKit 0x000000010c2eba2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
21 QuartzCore 0x000000010c0afec2 -[CALayer layoutSublayers] + 146
22 QuartzCore 0x000000010c0a46d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
23 QuartzCore 0x000000010c0a4546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
24 QuartzCore 0x000000010c010886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
25 QuartzCore 0x000000010c011a3a _ZN2CA11Transaction6commitEv + 462
26 QuartzCore 0x000000010c0120eb _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
27 CoreFoundation 0x000000010db8eca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
28 CoreFoundation 0x000000010db8ec00 __CFRunLoopDoObservers + 368
29 CoreFoundation 0x000000010db84a33 __CFRunLoopRun + 1123
30 CoreFoundation 0x000000010db84366 CFRunLoopRunSpecific + 470
31 GraphicsServices 0x000000010f611a3e GSEventRunModal + 161
32 UIKit 0x000000010c26b900 UIApplicationMain + 1282
33 Floadt 0x000000010a113c5f main + 111
34 libdyld.dylib 0x000000010fe26145 start + 1
35 ??? 0x0000000000000001 0x0 + 1
)
Here is my setup code for adding a UITableViewCell to the Table View Controller:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [self messageCellForRowAtIndexPath:indexPath];
}
- (MessageTableViewCell *)messageCellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MessageTableViewCell *cell = (MessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:MessengerCellIdentifier];
NSDictionary *instaPics = self.instagramData;
NSString *commentText = instaPics[#"comments"][#"data"][#"text"];
Message *message = self.messages[indexPath.row];
cell.titleLabel.text = message.username;
cell.bodyLabel.text = commentText;
if (message.attachment) {
cell.attachmentView.image = message.attachment;
cell.attachmentView.layer.shouldRasterize = YES;
cell.attachmentView.layer.rasterizationScale = [UIScreen mainScreen].scale;
}
cell.indexPath = indexPath;
cell.usedForMessage = YES;
if (cell.needsPlaceholder)
{
CGFloat scale = [UIScreen mainScreen].scale;
if ([[UIScreen mainScreen] respondsToSelector:#selector(nativeScale)]) {
scale = [UIScreen mainScreen].nativeScale;
}
CGSize imgSize = CGSizeMake(kAvatarSize*scale, kAvatarSize*scale);
[LoremIpsum asyncPlaceholderImageWithSize:imgSize
completion:^(UIImage *image) {
UIImage *thumbnail = [UIImage imageWithCGImage:image.CGImage scale:scale orientation:UIImageOrientationUp];
cell.thumbnailView.image = thumbnail;
cell.thumbnailView.layer.shouldRasterize = YES;
cell.thumbnailView.layer.rasterizationScale = [UIScreen mainScreen].scale;
}];
}
// Cells must inherit the table view's transform
// This is very important, since the main table view may be inverted
cell.transform = self.tableView.transform;
return cell;
}
Instagram JSON Data:
{
attribution = "<null>";
caption = {
"created_time" = 1430594453;
from = {
"full_name" = "Siwani Regmi";
id = 247899182;
"profile_picture" = "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/10948979_810376228999798_661235337_a.jpg";
username = "siwani_32";
};
id = 976219494210952254;
text = "perfect night with the most perfect man\Ud83d\Ude1b\Ud83c\Udf89\U2728 #seniorprom";
};
comments = {
count = 0;
data = (
);
};
"created_time" = 1430594453;
filter = Normal;
id = "976219491862142549_247899182";
images = {
"low_resolution" = {
height = 306;
url = "https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s306x306/e15/11191276_1060001617348197_1550964556_n.jpg";
width = 306;
};
"standard_resolution" = {
height = 640;
url = "https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/e15/11191276_1060001617348197_1550964556_n.jpg";
width = 640;
};
thumbnail = {
height = 150;
url = "https://scontent.cdninstagram.com/hphotos-xap1/t51.2885-15/s150x150/e15/11191276_1060001617348197_1550964556_n.jpg";
width = 150;
};
};
likes = {
count = 17;
data = (
{
"full_name" = "Bridget Carroll";
id = 223765496;
"profile_picture" = "https://igcdn-photos-e-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/11208422_409436919229236_670022667_a.jpg";
username = "bridget_carroll33";
},
{
"full_name" = "";
id = 190249955;
"profile_picture" = "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-19/10747956_726218724133062_1939114518_a.jpg";
username = hayleymarierussell;
},
{
"full_name" = "Jill Bracaglia";
id = 205453413;
"profile_picture" = "https://instagramimages-a.akamaihd.net/profiles/profile_205453413_75sq_1373835555.jpg";
username = "jilli_beanz";
},
{
"full_name" = "Priya Nakhre";
id = 177807366;
"profile_picture" = "https://igcdn-photos-c-a.akamaihd.net/hphotos-ak-xtp1/t51.2885-19/11098479_870674976323434_1264837026_a.jpg";
username = priyanakhre;
}
);
};
link = "https://instagram.com/p/2MOnSjQV5V/";
location = {
id = 764529229;
};
tags = (
seniorprom
);
type = image;
user = {
"full_name" = "Siwani Regmi";
id = 247899182;
"profile_picture" = "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/10948979_810376228999798_661235337_a.jpg";
username = "siwani_32";
};
"user_has_liked" = 0;
"users_in_photo" = (
{
position = {
x = "0.358666667";
y = "0.32";
};
user = {
"full_name" = "Sahan Pandey \U26bd";
id = 435571613;
"profile_picture" = "https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/10727510_301263856731264_1868575282_a.jpg";
username = pandeyexpress;
};
}
);
}
Related
my app is crashed when the user tapped on a marker (GMSMapVIew: didTapMarker) and myApp works good in 99% of the time, But sometimes it shows a crash on crashlytics. And it's so random occurred.
The crash report shows the following.
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000002f6ce97f4
-[BadgerMapView mapView:didTapMarker:]
Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x1f025653c objc_msgSend + 28
1 Badger 0x104d3af84 -[BadgerMapView mapView:didTapMarker:] + 1784 (BadgerMapView.m:1784)
2 CoreFoundation 0x1f106b900 __invoking___ + 144
3 CoreFoundation 0x1f0f4d4d0 -[NSInvocation invoke] + 292
4 CoreFoundation 0x1f0f4e104 -[NSInvocation invokeWithTarget:] + 60
5 Badger 0x104e940e0 -[GMSDelegateForward forwardInvocation:] + 4339744992
6 CoreFoundation 0x1f10697c0 ___forwarding___ + 636
7 CoreFoundation 0x1f106b75c _CF_forwarding_prep_0 + 92
8 Badger 0x104ea01fc -[GMSMapView didTapMarker:] + 20436
9 Badger 0x104eb8a88 -[GMSMarker wasTapped] + 120928
10 UIKitCore 0x21d1c3868 -[UIGestureRecognizerTarget _sendActionWithGestureRecognizer:] + 64
11 UIKitCore 0x21d1cba70 _UIGestureRecognizerSendTargetActions + 124
12 UIKitCore 0x21d1c9414 _UIGestureRecognizerSendActions + 316
13 UIKitCore 0x21d1c8940 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 760
14 UIKitCore 0x21d1bca1c _UIGestureEnvironmentUpdate + 2180
15 CoreFoundation 0x1f0ff55f8 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 32
16 CoreFoundation 0x1f0ff0320 __CFRunLoopDoObservers + 412
17 CoreFoundation 0x1f0ff089c __CFRunLoopRun + 1228
18 CoreFoundation 0x1f0ff00b0 CFRunLoopRunSpecific + 436
19 GraphicsServices 0x1f31f079c GSEventRunModal + 104
20 UIKitCore 0x21d59a978 UIApplicationMain + 212
21 Badger 0x104cb863c main + 17 (main.m:17)
22 libdyld.dylib 0x1f0ab58e0 start + 4
Below is my code where the app is crash.
BadgerMapView.m:1784
if (![waypt isKindOfClass:[NSNull class]]) This is the line where i got crash
- (BOOL)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *)marker
{
CLLocationCoordinate2D markerLocation = marker.position;
double tappedMarkerLattitude = markerLocation.latitude;
double tappedMarkerLongitude = markerLocation.longitude;
NSArray *waypoints =[MapViewController sharedInstance].wayPointsToShowOnRouteMode;
for (PlannerWaypoint *waypt in waypoints)
{
#try {
if (![waypt isKindOfClass:[NSNull class]]) {
if (![waypt isEqual:nil]) {
[MapViewController sharedInstance].currentWaypoint = waypt;
NSNumber *nextWayPointIndex = [MapViewController sharedInstance].currentWaypoint.modPosition;
NSNumber *prevWayPointIndex = [MapViewController sharedInstance].currentWaypoint.modPosition;
int value = [nextWayPointIndex intValue];
nextWayPointIndex = [NSNumber numberWithInt:value + 1];
NSUInteger nextWayPointIndexInt = [nextWayPointIndex integerValue];
prevWayPointIndex = [NSNumber numberWithInt:value - 1];
NSUInteger prevWayPointIndexInt = [prevWayPointIndex integerValue];
int waypointCount = (int)[waypoints count];
if (nextWayPointIndexInt > (waypointCount-1)) {
[MapViewController sharedInstance].nextWaypoint = [waypoints objectAtIndex:0];
}
else {
[MapViewController sharedInstance].nextWaypoint = [waypoints objectAtIndex:nextWayPointIndexInt];
}
if (prevWayPointIndexInt > (waypointCount-1)) {
[MapViewController sharedInstance].previousWaypoint = [waypoints objectAtIndex:(waypointCount-1)];
}
else {
[MapViewController sharedInstance].previousWaypoint = [waypoints objectAtIndex:prevWayPointIndexInt];
}
if([Utility isIphone] == NO) {
[[MapViewController sharedInstance] showMarkerSelectedAtMiddle:[MapViewController sharedInstance].currentWaypoint];
UIViewController *viewcontroller = [MenuViewController sharedInstance].presentedViewController;
if([viewcontroller.childViewControllers objectAtIndex:0]!=nil) {
RouteModeViewController *routeModeView = [viewcontroller.childViewControllers objectAtIndex:0];
[routeModeView.customerCardNameLabel setText:[MapViewController sharedInstance].waypointLabel];
}
} else {
UINavigationController *UINavController = (UINavigationController *)self.window.rootViewController.presentedViewController;
UIViewController *UIViewCon = [[UINavController viewControllers] lastObject];
if ([UIViewCon isKindOfClass:[MapViewController class]]) {
MapViewController *mapViewController = (MapViewController *)UIViewCon;
[mapViewController showMarkerSelectedAtMiddle:waypt];
}
}
[waypt release];
waypt = nil;
break;
}
}
} #catch (NSException *exception) {
NSLog(#"Exception in ProcessdidTapMarker: %#",exception);
[DeviceLoger log:[NSString stringWithFormat:#"Exception in ProcessdidTapMarker: %#",exception]];
}
}
return YES;
}
Does anybody have an idea?
Please help me, Because I'm facing this issue form a very long time
Thanks!
I am attempting to display an array which I receive from a JSON Dictionary onto a UITableView but I keep getting an error. I am trying to display all the comments for a given Instagram Picture onto a Table. Here is how I am attempting to display the cells:
MessageTableViewCell *cell = (MessageTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:MessengerCellIdentifier];
NSDictionary *instaPics = self.instagramData;
NSArray *commentArray = instaPics[#"comments"][#"data"];
NSString *commentText = [commentArray valueForKey:#"text"]; // Error occurs here
Message *message = self.messages[indexPath.row];
cell.titleLabel.text = message.username;
cell.bodyLabel.text = commentText;
Here is the error I receive:
-[__NSArrayI length]: unrecognized selector sent to instance 0x7f913052db10
2015-05-05 22:16:08.848 Floadt[6061:514032] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayI length]: unrecognized selector sent to instance 0x7f913052db10'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107d60c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010763cbb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000107d680ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000107cbe13c ___forwarding___ + 988
4 CoreFoundation 0x0000000107cbdcd8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000106543ab4 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 65
6 UIKit 0x000000010654390f -[UILabel textRectForBounds:limitedToNumberOfLines:] + 76
7 UIKit 0x00000001065473b9 -[UILabel _intrinsicSizeWithinSize:] + 170
8 UIKit 0x0000000106547499 -[UILabel intrinsicContentSize] + 76
9 UIKit 0x00000001069e5b6c -[UIView(UIConstraintBasedLayout) _generateContentSizeConstraints] + 33
10 UIKit 0x00000001069e5930 -[UIView(UIConstraintBasedLayout) _updateContentSizeConstraints] + 422
11 UIKit 0x00000001069ecd25 -[UIView(AdditionalLayoutSupport) updateConstraints] + 162
12 UIKit 0x0000000106547304 -[UILabel updateConstraints] + 274
13 UIKit 0x00000001069ec346 -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 242
14 UIKit 0x00000001069ec53e -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
15 CoreFoundation 0x0000000107c67354 CFArrayApplyFunction + 68
16 UIKit 0x00000001069ec2ed -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153
17 Foundation 0x0000000105b021be -[NSISEngine withBehaviors:performModifications:] + 155
18 UIKit 0x00000001069ec53e -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
19 CoreFoundation 0x0000000107c67354 CFArrayApplyFunction + 68
20 UIKit 0x00000001069ec2ed -[UIView(AdditionalLayoutSupport) _internalUpdateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 153
21 UIKit 0x00000001069ec53e -[UIView(AdditionalLayoutSupport) _updateConstraintsIfNeededAccumulatingViewsNeedingSecondPassAndViewsNeedingBaselineUpdate:] + 124
22 UIKit 0x00000001069eca0e __60-[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded]_block_invoke + 96
23 UIKit 0x00000001069ec6d6 -[UIView(AdditionalLayoutSupport) updateConstraintsIfNeeded] + 231
24 UIKit 0x00000001067d7531 -[UITableViewCellContentView updateConstraintsIfNeeded] + 94
25 UIKit 0x00000001069ecdde -[UIView(AdditionalLayoutSupport) _updateConstraintsAtEngineLevelIfNeeded] + 146
26 UIKit 0x00000001063e4a3d -[UIView(Hierarchy) _updateConstraintsAsNecessaryAndApplyLayoutFromEngine] + 114
27 UIKit 0x00000001063f0a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
28 QuartzCore 0x00000001061b4ec2 -[CALayer layoutSublayers] + 146
29 QuartzCore 0x00000001061a96d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
30 UIKit 0x00000001063e4675 -[UIView(Hierarchy) layoutBelowIfNeeded] + 607
31 Floadt 0x0000000104195848 -[SLKTextViewController viewWillAppear:] + 296
32 UIKit 0x00000001064a4fa1 -[UIViewController _setViewAppearState:isAnimating:] + 487
33 UIKit 0x00000001064c6395 -[UINavigationController _startCustomTransition:] + 887
34 UIKit 0x00000001064d23bf -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
35 UIKit 0x00000001064d2f0e -[UINavigationController __viewWillLayoutSubviews] + 43
36 UIKit 0x000000010661d715 -[UILayoutContainerView layoutSubviews] + 202
37 UIKit 0x00000001063f0a2b -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
38 QuartzCore 0x00000001061b4ec2 -[CALayer layoutSublayers] + 146
39 QuartzCore 0x00000001061a96d6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
40 QuartzCore 0x00000001061a9546 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
41 QuartzCore 0x0000000106115886 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
42 QuartzCore 0x0000000106116a3a _ZN2CA11Transaction6commitEv + 462
43 UIKit 0x000000010636d626 _UIApplicationHandleEventQueue + 2140
44 CoreFoundation 0x0000000107c94431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
45 CoreFoundation 0x0000000107c8a2fd __CFRunLoopDoSources0 + 269
46 CoreFoundation 0x0000000107c89934 __CFRunLoopRun + 868
47 CoreFoundation 0x0000000107c89366 CFRunLoopRunSpecific + 470
48 GraphicsServices 0x0000000109716a3e GSEventRunModal + 161
49 UIKit 0x0000000106370900 UIApplicationMain + 1282
50 Floadt 0x0000000104218c5f main + 111
51 libdyld.dylib 0x0000000109f2b145 start + 1
52 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Here is an example copy of the JSON:
{
attribution = "<null>";
caption = {
"created_time" = 1430877943;
from = {
"full_name" = "Shreya M.";
id = 25085898;
"profile_picture" = "https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-19/10890672_320752588135679_1815913692_a.jpg";
username = "shreya_mandava";
};
id = 978597576956579585;
text = "9+10????";
};
comments = {
count = 2;
data = (
{
"created_time" = 1430878007;
from = {
"full_name" = "Aleesha Toteja";
id = 17117902;
"profile_picture" = "https://instagramimages-a.akamaihd.net/profiles/profile_17117902_75sq_1373927314.jpg";
username = leeshtotes;
};
id = 978598112887967529;
text = "DIRT \Ud83d\Ude3b";
},
{
"created_time" = 1430878307;
from = {
"full_name" = "Shritha M.";
id = 375799796;
"profile_picture" = "https://igcdn-photos-f-a.akamaihd.net/hphotos-ak-xpf1/t51.2885-19/10454159_1056687271012469_2048676049_a.jpg";
username = "shritha_m";
};
id = 978600630846098439;
text = sigh;
}
);
};
"created_time" = 1430877943;
filter = Normal;
id = "978597574314167442_25085898";
images = {
"low_resolution" = {
height = 306;
url = "https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s306x306/e15/11241842_1401517966839213_670743424_n.jpg";
width = 306;
};
"standard_resolution" = {
height = 640;
url = "https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/e15/11241842_1401517966839213_670743424_n.jpg";
width = 640;
};
thumbnail = {
height = 150;
url = "https://scontent.cdninstagram.com/hphotos-xfa1/t51.2885-15/s150x150/e15/11241842_1401517966839213_670743424_n.jpg";
width = 150;
};
};
likes = {
count = 22;
data = (
{
"full_name" = "Ronak Chopra";
id = 347652824;
"profile_picture" = "https://scontent.cdninstagram.com/hphotos-xpa1/t51.2885-19/11142328_1644920965736964_1040275960_a.jpg";
username = "conak_rhopra";
},
{
"full_name" = "emily bach";
id = 292615252;
"profile_picture" = "https://igcdn-photos-a-a.akamaihd.net/hphotos-ak-xap1/t51.2885-19/10454121_1558984144374824_122699173_a.jpg";
username = "emily_bach_";
},
{
"full_name" = "\Ud83c\Udf38Trisha\Ud83c\Udf38";
id = 303629882;
"profile_picture" = "https://igcdn-photos-g-a.akamaihd.net/hphotos-ak-xfp1/t51.2885-19/10955125_708435799269374_749376734_a.jpg";
username = trishddishh;
},
{
"full_name" = "Shritha M.";
id = 375799796;
"profile_picture" = "https://igcdn-photos-f-a.akamaihd.net/hphotos-ak-xpf1/t51.2885-19/10454159_1056687271012469_2048676049_a.jpg";
username = "shritha_m";
}
);
};
link = "https://instagram.com/p/2UrU8bDgyS/";
location = {
id = 772010926;
latitude = "38.913782928";
longitude = "-77.383238738";
name = "ft. dirt";
};
tags = (
);
type = image;
user = {
"full_name" = "Shreya M.";
id = 25085898;
"profile_picture" = "https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xaf1/t51.2885-19/10890672_320752588135679_1815913692_a.jpg";
username = "shreya_mandava";
};
"user_has_liked" = 0;
"users_in_photo" = (
{
position = {
x = "0.6703125";
y = "0.246875";
};
user = {
"full_name" = "John Nguyen";
id = 1477626916;
"profile_picture" = "https://igcdn-photos-d-a.akamaihd.net/hphotos-ak-xfp1/t51.2885-19/11018467_1431648953794187_659343544_a.jpg";
username = bumbonguyen;
};
}
);
}
You are trying to get a value from key in a NSArray on:
[commentArray valueForKey:#"text"];
NSArray is not a dictionary has not keys (has multiple comments), should be accessed by his index.
[[commentArray objectAtIndex:0] valueForKey:#"text"];
Probably you will want, iterate over the comments and on each comment get his "text"
You can replace this line :
NSString *commentText = [commentArray valueForKey:#"text"];
with
for (NSDictionary *comment in commentArray ) {
NSString *commentText = [comment valueForKey:#"text"];
cell.bodyLabel.text = commentText;
}
Gonzalo is right. Your accessing commentArray like a NSDictionary but it is actually a NSArray. That causes the crash.
NSArray *commentArray = instaPics[#"comments"][#"data"];
It looks like a wrong access of key value..
As per my understanding you are trying to get value of comments.
your Json data contains root & child key value like,
comments
count
Data
caption
images
likes
...
Here your Comments having child value like count,data.
So can write the code to fetch value of comment > data>text
--------1--------
NSMutableDictionary *response = [[[json valueForKey:#"comments"] objectAtIndex:0]mutableCopy];
NSMutableDictionary *data = [[[response valueForKey:#"data"] objectAtIndex:0]mutableCopy];
NSString *text = [data valueForKey:#"text"];
----OR----2--------
NSMutableDictionary *response = [[[json valueForKey:#"comments"] objectAtIndex:0]mutableCopy];
NSArray *textarr=[response valueForKey:#"text"];
I have the following code and receive the error code indicated in title:
This is the only messages i send to User object (other than initialising it by using "new")
When I out comment addObject: it doesn't complain.
Can anybody help? Thanks!
self.freshUser.name = self.name.text;
self.freshUser.age = (int)self.age.text;
self.freshUser.gender = self.gender.text;
//NSLog(#"%#",[NSThread callStackSymbols]);
[appDelegate.users addObject:self.freshUser];
(My user object subclasses NSObject. it has more property that I don't use. just a little extra info)
-(UITableViewCell *)tableView:(UITableView *)tableViewPara cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UserCell *cell = [tableViewPara dequeueReusableCellWithIdentifier:usersTableIdentifier forIndexPath:indexPath];
if(indexPath.row == [appDelegate.users count]){
cell.nameLabel.text = #"+";
cell.nameLabel.font = [UIFont systemFontOfSize:36];
cell.bgImg.image = [UIImage imageNamed:#"background_gray"];
cell.statusImg.image = nil;
}else{
cell.nameLabel.text = appDelegate.users[indexPath.row];
cell.nameLabel.font = [UIFont systemFontOfSize:17];
cell.bgImg.image = [UIImage imageNamed:#"background_dark_red"];
cell.statusImg.image = [UIImage imageNamed:#"icon_cloud"];
}
cell.nameLabel.textAlignment = NSTextAlignmentCenter;
cell.nameLabel.textColor = [UIColor whiteColor];
cell.nameLabel.backgroundColor = [UIColor clearColor];
return cell;
}
space
0 CoreFoundation 0x000000010ff1bf35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010fbb4bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010ff2304d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010fe7b27c ___forwarding___ + 988
4 CoreFoundation 0x000000010fe7ae18 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001104d034b -[UILabel _setFont:] + 101
6 Raymio 0x000000010f67857f -[StartViewController tableView:cellForRowAtIndexPath:] + 991
7 UIKit 0x00000001103ff4b3 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 508
8 UIKit 0x00000001103defb1 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2846
9 UIKit 0x00000001103f4e3c -[UITableView layoutSubviews] + 213
10 UIKit 0x0000000110381973 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 521
11 QuartzCore 0x0000000113c09de8 -[CALayer layoutSublayers] + 150
12 QuartzCore 0x0000000113bfea0e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x0000000113bfe87e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000113b6c63e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
15 QuartzCore 0x0000000113b6d74a _ZN2CA11Transaction6commitEv + 390
16 QuartzCore 0x0000000113b6ddb5 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
17 CoreFoundation 0x000000010fe50dc7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x000000010fe50d20 __CFRunLoopDoObservers + 368
19 CoreFoundation 0x000000010fe46b53 __CFRunLoopRun + 1123
20 CoreFoundation 0x000000010fe46486 CFRunLoopRunSpecific + 470
21 GraphicsServices 0x00000001134fd9f0 GSEventRunModal + 161
22 UIKit 0x0000000110308420 UIApplicationMain + 1282
23 Raymio 0x000000010f678a83 main + 115
24 libdyld.dylib 0x00000001124ab145 start + 1
This line:
cell.nameLabel.text = appDelegate.users[indexPath.row];
You're trying to set a User object to the text of a label field. That's not going to work. You'll want this or something close:
cell.nameLabel.text = ((User *)appDelegate.users[indexPath.row]).name;
You shared your stack trace with us. A useful technique is to look in it for anything that references code you wrote. You may notice that line 6 references your StartViewController:
6 Raymio 0x000000010f67857f -[StartViewController tableView:cellForRowAtIndexPath:] + 991
You can show the relevant line of code by typing source list command using that address in the third column:
(lldb) source list -a 0x000000010f67857f
43 cell.nameLabel.text = #"+";
44 cell.nameLabel.font = [UIFont systemFontOfSize:36];
45 cell.bgImg.image = [UIImage imageNamed:#"background_gray"];
46 cell.statusImg.image = nil;
47 }else{
-> 48 cell.nameLabel.text = appDelegate.users[indexPath.row];
49 cell.nameLabel.font = [UIFont systemFontOfSize:17];
50 cell.bgImg.image = [UIImage imageNamed:#"background_dark_red"];
51 cell.statusImg.image = [UIImage imageNamed:#"icon_cloud"];
52 }
Clearly your line numbers and memory addresses will vary, but hopefully this will illustrate the idea. Scan the stack trace for anything that references your code, and examine that line of code for any potential issues.
By the way, this discussion. also shows you how to use the -[StartViewController tableView:cellForRowAtIndexPath:] + 991 of the stack trace to show the relevant line of code.
I have a NSDictionary that I add to a mutable array but when I try add the array to populate a uitableview I get an error.
NSMutableArray *array = [[NSMutableArray alloc] init];
for (id element in self.categoriesMutableNameArray) {
[array addObject:#"No"];
}
self.categoryDict = #{ #"title" : self.categoriesMutableNameArray, #"selected" : array};
self.categoryArr = [[NSMutableArray alloc] init];
self.categoryMutableDict = [NSMutableDictionary dictionaryWithDictionary:self.categoryDict];
[self.categoryArr addObject:self.categoryDict];
and the following categoryArr is printed like this:
2014-02-27 15:09:07.397 App[7982:70b] (
{
selected = (
No,
No,
No,
No,
No,
No,
No,
No,
No,
No,
No,
No,
No,
No
);
title = (
"Fashion - Women",
"Fashion - Men",
Kids,
"Accessories - Women",
"Accessories - Men",
"Styling / Hair",
Inspiration,
"Decoration / Architecture",
"Great Places",
"Art / Design",
"Music / Movie / Books",
"Food / Drink",
"Gadgets / Tech",
Rides
);
}
)
The trouble I am having is in the uitableview cellforrowatindexpath method I try and add the title key for the categoryArr to populate the uitableview and I get the following error on this line:
UILabel *categoryLabel = (UILabel *)[cell viewWithTag:111];
categoryLabel.text = [NSString stringWithFormat:#"%#",[[self.categoryArr objectAtIndex:indexPath.row] objectForKey:#"title"];
And the error log:
2014-02-27 15:24:33.804 App[8153:70b] -[__NSArrayM length]: unrecognized selector sent to instance 0xa9bc3a0
2014-02-27 15:24:33.807 App[8153:70b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM length]: unrecognized selector sent to instance 0xa9bc3a0'
*** First throw call stack:
(
0 CoreFoundation 0x020c75e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x01e4a8b6 objc_exception_throw + 44
2 CoreFoundation 0x02164903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x020b790b ___forwarding___ + 1019
4 CoreFoundation 0x020b74ee _CF_forwarding_prep_0 + 14
5 Foundation 0x006e18ed -[NSConcreteMutableAttributedString replaceCharactersInRange:withString:] + 39
6 Foundation 0x006e255a -[NSConcreteMutableAttributedString initWithString:attributes:] + 293
7 UIKit 0x01172bc6 -[UILabel _setText:] + 97
8 UIKit 0x01172d84 -[UILabel setText:] + 40
9 App 0x00047ebd -[PiccImageCategoriesViewController tableView:cellForRowAtIndexPath:] + 1533
10 UIKit 0x010b461f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
11 UIKit 0x010b46f3 -[UITableView _createPreparedCellForGlobalRow:] + 69
12 UIKit 0x01098774 -[UITableView _updateVisibleCellsNow:] + 2378
13 UIKit 0x010abe95 -[UITableView layoutSubviews] + 213
14 UIKit 0x01030267 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
15 libobjc.A.dylib 0x01e5c81f -[NSObject performSelector:withObject:] + 70
16 QuartzCore 0x00c8e2ea -[CALayer layoutSublayers] + 148
17 QuartzCore 0x00c820d4 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
18 QuartzCore 0x00c81f40 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
19 QuartzCore 0x00be9ae6 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
20 QuartzCore 0x00beae71 _ZN2CA11Transaction6commitEv + 393
21 QuartzCore 0x00beb544 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
22 CoreFoundation 0x0208f4ce __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
23 CoreFoundation 0x0208f41f __CFRunLoopDoObservers + 399
24 CoreFoundation 0x0206d344 __CFRunLoopRun + 1076
25 CoreFoundation 0x0206cac3 CFRunLoopRunSpecific + 467
26 CoreFoundation 0x0206c8db CFRunLoopRunInMode + 123
27 GraphicsServices 0x027779e2 GSEventRunModal + 192
28 GraphicsServices 0x02777809 GSEventRun + 104
29 UIKit 0x00fc5d3b UIApplicationMain + 1225
30 App 0x0001406d main + 141
31 libdyld.dylib 0x02f4d70d start + 1
32 ??? 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Thanks
The return of [[self.categoryArr objectAtIndex:indexPath.row] objectForKey:#"title"]; is a array of NSString, categoryLabel.text = [NSString stringWithFormat:#"%#", /*the return array*/]; this is the problem.
Maybe what you want is:
NSArray *categoryDetailArr = [[self.categoryArr objectAtIndex:indexPath.section] objectForKey:#"title"];
categoryLabel.text = [[categoryDetailArr objectAtIndex:indexPath.row];
Write this code
categoryLabel.text = [[[self.categoryArr objectAtIndex:0] objectForKey:#"title"]objectAtIndex:indexPath.row];
instead OF
categoryLabel.text = [NSString stringWithFormat:#"%#",[[self.categoryArr objectAtIndex:indexPath.row] objectForKey:#"title"];
And plz check that in UITableView dataSource methods i.e
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [categoryLabel objectAtIndex:0]valueForKey:#"selected"].count;
}
OR
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [categoryLabel objectAtIndex:0]valueForKey:#"title"].count;
}
I'm building a Xamarin.iOS app, I have a UITableView with a custom UITableViewCell, when I add data from server to the table or if I begin to scroll up and down fast, the app crashes and give me this error log:
Native stacktrace:
>0 CardReader_iOS 0x003b5ed5 mono_handle_native_sigsegv + 260
>1 CardReader_iOS 0x003befad mono_sigsegv_signal_handler + 176
>2 libsystem_platform.dylib 0x3a600063 _sigtramp + 42
>3 CardReader_iOS 0x000d0798
CardReader_iOS_ICTableContactSource_GetCell_MonoTouch_UIKit_UITableView_MonoTouch_Foundation_NSIndexPath + 164
>4 CardReader_iOS 0x002740d0
wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
>5 CardReader_iOS 0x003c1087 mono_jit_runtime_invoke + 1134
>6 CardReader_iOS 0x003fbd2d mono_runtime_invoke + 88
>7 CardReader_iOS 0x003914af
native_to_managed_trampoline_CardReader_iOS_ICTableContactSource_GetCell + 402
8 UIKit 0x3256da5b + 410
>9 UIKit 0x32515e7d <redacted> + 1804
>10 UIKit 0x32515699 <redacted> + 184
>11 UIKit 0x3243bda3 <redacted> + 346
>12 QuartzCore 0x320c2c6b <redacted> + 142
>13 QuartzCore 0x320be47b <redacted> + 350
>14 QuartzCore 0x320be30d <redacted> + 16
>15 QuartzCore 0x320bdd1f <redacted> + 230
>16 QuartzCore 0x320bdb2f <redacted> + 314
>17 QuartzCore 0x32112825 <redacted> + 516
>18 IOMobileFramebuffer 0x34d0876d <redacted> + 104
>19 IOKit 0x309aaa75 IODispatchCalloutFromCFMessage + 248
>20 CoreFoundation 0x2fc88e21 <redacted> + 136
>21 CoreFoundation 0x2fc939df <redacted> + 34
>22 CoreFoundation 0x2fc9397b <redacted> + 346
>23 CoreFoundation 0x2fc9214f <redacted> + 1398
>24 CoreFoundation 0x2fbfcc27 CFRunLoopRunSpecific + 522
>25 CoreFoundation 0x2fbfca0b CFRunLoopRunInMode + 106
>26 GraphicsServices 0x348ec283 GSEventRunModal + 138
>27 UIKit 0x324a0049 UIApplicationMain + 1136
>28 CardReader_iOS 0x00166e40
wrapper_managed_to_native_MonoTouch_UIKit_UIApplication_UIApplicationMain_int_string___intptr_intptr + 272
29 CardReader_iOS 0x00143244 MonoTouch_UIKit_UIApplication_Main_string___string_string + 300
>30 CardReader_iOS 0x000aa148 CardReader_iOS_Application_Main_string__ + 172
>31 CardReader_iOS 0x002740d0
wrapper_runtime_invoke_object_runtime_invoke_dynamic_intptr_intptr_intptr_intptr + 200
>32 CardReader_iOS 0x003c1087 mono_jit_runtime_invoke + 1134
>33 CardReader_iOS 0x003fbd2d mono_runtime_invoke + 88
>34 CardReader_iOS 0x003ff8b5 mono_runtime_exec_main + 276
>35 CardReader_iOS 0x003ff705 mono_runtime_run_main + 424
>36 CardReader_iOS 0x003af6e1 mono_jit_exec + 48
>37 CardReader_iOS 0x00432704 main + 2468
>38 libdyld.dylib 0x3a4e5ab7 <redacted> + 2
> Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
Here Is My Code:
This method execute after server callback I fill data from server into a new List
public void addContacts(){
InvokeOnMainThread (delegate {
try{
tableContact.BeginUpdates();
items.AddRange(itemsAdd);
ICGlobal.contacts.AddRange(itemsAdd);
tableContact.ReloadData();
tableContact.SetNeedsDisplay();
tableContact.EndUpdates();
}catch(Exception e){
Console.WriteLine(e.StackTrace);
}
ICLayoutMgr.Get().SetBusy(false);
tableContact.ScrollEnabled = true;
});
}
this is the Custom cell class
public class ICTableContactCell : UITableViewCell
{
ICContactTableItem item;
ICContactCellView viewData;
public ICTableContactCell (ICContactTableItem item,NSString cellId) : base(UITableViewCellStyle.Default, cellId )
{
ContentView.BackgroundColor = UIColor.White;
this.item = item;
viewData = new ICContactCellView (this.item);
var view = new UIView (ContentView.Frame);
view.BackgroundColor = UIColor.Gray;
this.SelectionStyle = UITableViewCellSelectionStyle.Default;
this.SelectedBackgroundView = view;
ContentView.Add (viewData);
}
public override void LayoutSubviews ()
{
base.LayoutSubviews ();
viewData.Frame = ContentView.Bounds;
viewData.SetNeedsDisplay ();
}
public void UpdateCell (ICContactTableItem titem){
this.item = titem;
viewData.UpdateCell (titem);
}
}
public class ICContactCellView:UIView{
UILabel uiTitle;
UILabel uiCompany;
UIImageView imgSelected;
UIImageView imgDetail;
ICContactTableItem item;
static UIImage arrow=UIImage.FromFile("btnArrow.png");
static UIImage address=UIImage.FromFile("btnaddress.png");
public ICContactCellView (ICContactTableItem item)
{
this.item = item;
BackgroundColor = UIColor.White;
float yOffset = 5f;
UIColor otherColor = UIColor.Black;
uiTitle = IOTM.GUI.CreateLabel ("TITLE", yOffset+10f, yOffset, 200f, 24f, otherColor, "Helvetica-Bold", 14f);
uiCompany = IOTM.GUI.CreateLabel ("Comapany", yOffset+10f, yOffset + 16f, 200f, 24f, otherColor, "HelveticaNeue", 13f);
imgSelected =new UIImageView(){
Image = address,
Frame = IOTM.GUI.CreateFrame( yOffset+235f, yOffset+5f, 30, 30)
};
imgDetail = new UIImageView () {
Image = arrow,
Frame = IOTM.GUI.CreateFrame (280f, yOffset + 15f, 10, 10)
};
Add (uiTitle);
Add (uiCompany);
Add (imgSelected);
Add (imgDetail);
UpdateCell (this.item);
}
public void UpdateCell (ICContactTableItem titem){
this.item = titem;
if (item.index % 2 == 0)
BackgroundColor = ICGlobal.Gray;
else {
BackgroundColor = UIColor.White;
}
uiCompany.Text = "Company: " + item.enterprise;
uiTitle.Text = item.firstName+" "+item.lastName;
SetNeedsDisplay ();
}
}
TableViewSource
public class ICTableContactSource : UITableViewSource
{
public ICTableContactCell cell;
private static ICLoadMoreCell loadMore;
private ICContactTableItem itemC;
protected List<ICContactTableItem> tableItems;
protected string cellIdentifier;
public UINavigationController ParentNavigation{ get; set; }
public ICTableContactSource(List<ICContactTableItem> tl)
{
cellIdentifier = "contactCellID";
tableItems = tl;
}
public override int RowsInSection(UITableView t, int i)
{
return tableItems.Count+1;
}
public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
{
if (indexPath.Row == tableItems.Count) {
loadMore = tableView.DequeueReusableCell ("LoadingCell") as ICLoadMoreCell;
if (loadMore == null) {
loadMore = new ICLoadMoreCell (new NSString ("LoadingCell"));
}
loadMore.UpdateCell (null, 0);
return loadMore;
} else {
cell = tableView.DequeueReusableCell (cellIdentifier) as ICTableContactCell;
itemC = tableItems [indexPath.Row];
if (cell == null) {
itemC.index = indexPath.Row;
cell = new ICTableContactCell (itemC, new NSString (cellIdentifier));
cell.UpdateCell (itemC);
} else {
itemC.index = indexPath.Row;
cell.UpdateCell (itemC);
}
}
return cell as UITableViewCell;
}
public override void WillDisplay (UITableView tableView, UITableViewCell cell, NSIndexPath indexPath)
{
if (cell is ICLoadMoreCell) {
ICGlobal.currentContactView.loadMore ();
}
}