hi i am new to iphone programing,i am using EGOPhotViewer and want to show images by using this code,
for ( recipeImages in recipeImages.imgArray) {
photo = [[MyPhoto alloc] initWithImageURL:[NSURL URLWithString:recipeImages.recipie_img_url]name:recipeImages.recipe_name];
NSLog(#"%#",recipeImages.recipie_img_url);
MyPhotoSource *source = [[MyPhotoSource alloc] initWithPhotos:[NSArray arrayWithObjects:photo ,nil]];
photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];
}
[APPDELEGATE.navigationController pushViewController:photoController animated:YES];
and i get this error
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2147483648 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x225f012 0x2084e7e 0x2214b44 0x9e1e4 0xa46c4 0x1b45dc9 0x22b90c5 0x2213efa 0x1a7a482 0x1a8d73b 0xa9d7c 0xa6a4e 0xa5081 0xa0499 0x10af753 0x10afa7b 0x10bd590 0x10c55bd 0x10c5eab 0x10c64a3 0x10c6098 0x5bad6 0x2098705 0xfcf920 0xfcf8b8 0x1090671 0x1090bcf 0x108fd38 0xfff33f 0xfff552 0xfdd3aa 0xfcecf8 0x2c15df9 0x2c15ad0 0x21d4bf5 0x21d4962 0x2205bb6 0x2204f44 0x2204e1b 0x2c147e3 0x2c14668 0xfcc65c 0x263a 0x2545)
libc++abi.dylib: terminate called throwing an exception
i solved this by writing this code
NSMutableArray *localImagesArray = [[NSMutableArray alloc] init];
for ( recipeImages in recipeImages.imgArray) {
photo = [[MyPhoto alloc] initWithImageURL:[NSURL URLWithString:recipeImages.recipie_img_url]name:recipeImages.recipe_name];
NSLog(#"%#",recipeImages.recipie_img_url);
NSLog(#"%#", [photo debugDescription]);
[localImagesArray addObject:photo];
}
MyPhotoSource *source = [[MyPhotoSource alloc] initWithPhotos:localImagesArray];
photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];
[APPDELEGATE.navigationController pushViewController:photoController animated:YES];
}
[__NSArrayI objectAtIndex:]: index 2147483648 beyond bounds [0 .. 0]'
2147483648 is NSNotFound. Somewhere in your code, or the code of a library you are using, something like indexOfObject: is being used on one array, and that index is being used to get a value from another array, and it is failing.
Your for loop looks very suspect. You're assigning a value to photoController at the end of each iteration, meaning only the value you assign last will actually get used. I'm not familiar with the library you're using but you probably want to be building up an array of MyPhoto objects before passing them to a single photoController.
Make sure initWithImageURL: name: inside MyPhoto returns self.
Verify this with NSLog(#"%#", [photo debugDescription]);
Related
I am using an NSArray to load objects into my UICollectionView. The UICollectionView has a UIPageViewController associated with it where I am grabbing the index for each page. Depending on what page you are on, I want to load different objects.
I try to do that using the following:
NSDictionary *dictionary = [[NSDictionary alloc] init];
if (self.index == 0) {
dictionary = [self.imageArray objectAtIndex:indexPath.row];
} else if (self.index == 1) {
dictionary = [self.imageArray objectAtIndex:12 + indexPath.row];
NSLog(#"%#", self.imageArray);
} else if (self.index == 2) {
dictionary = [self.imageArray objectAtIndex:24 + indexPath.row];
}
Where self.index is the page you are on.
However, I keep getting the following crash:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 48 beyond bounds [0 .. 47]'
However, my array does have 48 objects. There are 12 objects loaded on each page.
Does it have anything to do with me setting the dictionary each time? Only thing I could think of....
Help would be appreciated.
Instead of using those ugly ifs and twisted logic, try to structure your model better. One way of doing this would be to have an array of arrays: each page an array of images. You'd know the pages count from the model and accessing the right image would be as simple as self.images[self.index][indexpath.row] You could also use an UIcollectionview with each page a section.
I have encountered a strange crash on my code.
Here's the code :
UIView *tableHeaderView = self.tableView.tableHeaderView;
CGRect frame = tableHeaderView.frame;
frame.size.height = 0;
tableHeaderView.frame = frame;
self.tableView.tableHeaderView = tableHeaderView;
The crash occurred on the last line of the code.
And, here is the log
Terminating app due to uncaught exception 'NSRangeException', reason:
'*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(0x345ae2a3 0x3c25397f 0x344f9b75 0x1a7055 0x363ebb8f 0x363d702b 0x363d7599 0x363d740d 0x3642b22b 0x1a0d77 0x363d5595 0x3642a14b 0x3642a091 0x36429f75 0x36429e99 0x364295d9 0x364294c1 0x364764d1 0x36428861 0x36428713 0x364a4399 0x364508fb 0x36691619 0x364a39b9 0x364a1fe7 0x26c8a1 0x221997 0x34ee96fd 0x34e291f9 0x34e29115 0x3428b45f 0x3428ab43 0x342b2fcb 0x344f474d 0x342b342b 0x3421703d 0x34583683 0x34582ee9 0x34581cb7 0x344f4ebd 0x344f4d49 0x380b82eb 0x3640a301 0x10819f 0x3c68ab20)
libc++abi.dylib: terminate called throwing an exception
I really don't have any idea what happened on my code.
Any advice are helpful for me!
Thank you.
You definitely initialise some array in your class firstly check your array by placing NSLog that it should have some value or it is null. I think it is null thats why they creating a problem.
If you want to change the headerView for a table, this is the proper way to do it:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:kHeaderFrame];
return headerView;
}
My Application is crashing when I run it on the iPad but works 100% on the iPad simulator I am using Version 4.6.1 of Xcode and Version 6.1.3 on the iPad.
The problem lies where I am trying to pass the value of an int between segues
in my .h
#property (nonatomic, assign)int currentQuestion;
in my .m
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"level1correct"]){
AddLevel1IncorrectViewController *incorrect = [segue destinationViewController];
incorrect.CQValue = self.currentQuestion;
}}
AddLevel1Incorrect.h
#property (nonatomic, assign)int CQValue;
AddLevel1Incorrect.m
#synthesize CQValue = _CQValue;
- (void)imageSelect{
int numItems = [arrayPath count];
NSMutableArray *left = [NSMutableArray arrayWithCapacity:numItems];
NSMutableArray *right = [NSMutableArray arrayWithCapacity:numItems];
for (NSDictionary *itemData in arrayPath) {
[left addObject:[itemData objectForKey:#"L"]];
[right addObject:[itemData objectForKey:#"R"]];
}
NSLog(#" value of %d CQValue ", self.CQValue);
leftImageViewer.image = [UIImage imageNamed:left[self.CQValue]];//this is the point where the crash happens
rightImageViewer.image = [UIImage imageNamed:right[self.CQValue]];
}
The interesting thing is it does display the correct value in the NSLog in the Console as you will see at the top of the Crash Message
2013-04-03 22:50:00.404 thefyp[1506:907] value of 1 CQValue
2013-04-03 22:50:00.408 thefyp[1506:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
*** First throw call stack:
Any ideas where I am going wrong here?
Your code is very brittle, meaning it makes a lot of assumptions about the data it's working with without verifying the data is accurate.
You never check the bounds of the array before you access it. self.CQValue is 1, but in this case the array itself is empty. so left[self.CQValue], is left[1], which is invalid.
Check arrayPath to make sure it's not empty.
I have a piece of code where I'm trying to add items to an AVQueuePlayer iteratively, as follows:
for (int i = tempNowPlayingIndex - 1; i < [_itemsForPlayer count]; i++) {
[self insertItem:[_itemsForPlayer objectAtIndex:i] afterItem:nil];
}
_itemsForPlayer is a NSMutableArray containing AVPlayerItems.
Whenever I reach this line on execution, however I get a
'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
error. I know that the line responsible is
[self insertItem:[_itemsForPlayer objectAtIndex:i] afterItem:nil];
because commenting that line out removes the error. I had assumed that the problem was that [_itemsForPlayer objectAtIndex:i] wasn't returning an AVPlayerItem, but adding a print statement to print [_itemsForPlayer objectAtIndex:i] gives me:
<AVPlayerItem: 0x2002be60, asset = <AVURLAsset: 0x2003c0e0, URL = ipod-library://item/item.mp3?id=8966039988459606203>>
So the code should be able to add it to the AVQueuePlayer just fine. Does anyone have any ideas?
EDIT: Many thanks to #borrrden, who answered the question in a comment - I've overridden insertItem:afterItem elsewhere in the class, and the error was coming from an issue in the overridden method. Talk about your stupid mistakes - thanks again, Borrrden!
In my game, when I load a new level, the previous level seems to be still remaining in the view.. Each level has its own class and they all draw something on the screen. So if I have 2 or more levels of images loaded, that makes my game too slow. What can I do to unload the previous level? Thanks in advance..
- (void) finishedLevel: (Level *) level
{
levelNumber++;
levelClass = NSClassFromString([NSString stringWithFormat:
#"Level_%d", levelNumber]);
if (!levelClass) levelClass = [Level class];
currentLevel = [[levelClass alloc] initWithView: self.mainView];
self.mainView.levelLabel.text = [NSString stringWithFormat:#"Level %d", levelNumber];
gameRunning = NO;
}
I tried using the following but didn't really work
levelClass = NSClassFromString([NSString stringWithFormat:#"Level_%d", levelNumber-1]);
[levelClass removeFromSuperview];
Error message
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[Level_1 removeFromSuperview]: unrecognized selector sent to class 0x107644'