This is My Code:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
productScreen *screen=[[productScreen alloc]init];
screen =[self.storyboard instantiateViewControllerWithIdentifier:#"product"];
[self presentViewController:screen animated:YES completion:nil];
}
when ever i select the collection cell its give me a error .
ERROR
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSConcreteScanner setScanLocation:]: Index 1 out of bounds; string length 0'
I searched many sites but i cant get the answer properly so any experts please help me to fix this error.
When you call:
screen =[self.storyboard instantiateViewControllerWithIdentifier:#"product"];
[self presentViewController:screen animated:YES completion:nil];
the view is loaded. you then have code:
self.view.backgroundColor=[UIColor colorFromHexString:#""];
which is trying to parse an invalid string and throwing an error.
Also, you should remove:
productScreen *screen=[[productScreen alloc]init];
because you're creating an instance of productScreen which is never used so it's a waste of memory, and your class productScreen should be called ProductScreen to follow naming conventions.
Related
I am trying to do Peek and Pop in my iOS 9 capable app. The view in question has a UITableView, so I have in my code:
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location {
// check if we're not already displaying a preview controller
if ([self.presentedViewController isKindOfClass:[WebViewController class]]) {
return nil;
}
// shallow press: return the preview controller here (peek)
self.webViewController = [[[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
return self.webViewController;
}
- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
// deep press: bring up the commit view controller (pop)
self.webViewController = [[[WebViewController alloc] initWithNibName:#"WebViewController" bundle:[NSBundle mainBundle]] autorelease];
[self showViewController:self.webViewController sender:self];
}
WebViewController is the ViewController I have already set up to display the content when the row of the tableview is selected. The error I get is:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSCFConstantString stringByAppendingString:]: nil argument'
*** First throw call stack:
(0x182160f5c 0x19764bf80 0x182160ea4 0x182fb8868 0x1001307a4 0x1876cf9ac 0x1876cf720 0x187a025f8 0x187960844 0x18796cde4 0x1876a91e4 0x182117c30 0x1821159d4 0x182115e04 0x182044dc0 0x18d4e0088 0x18771ef60 0x10014ca68 0x197e6a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
Your log it's saying exactly what is wrong with your code:
-[__NSCFConstantString stringByAppendingString:]: nil argument'
You are performing stringByAppendingString passing a value that is nil
Also, autorelease is not used anymore if you are using ARC (it's default by now)
So I'm getting this error -
*** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /SourceCache/UIFoundation_Sim/UIFoundation-258.1/UIFoundation/TextSystem/NSLayoutManager_Private.m:1510
2014-01-13 18:58:55.829 ReviewApp[1678:3c03] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
The error is apparent..but I'm not sure why it's happening. This is how I'm registering the nib -
UINib* dqNib = [UINib nibWithNibName:#"DQCardView" bundle:nil];
UINib* simpleListNib = [UINib nibWithNibName:#"SimpleListCell" bundle:nil];
UINib* photoPostNib = [UINib nibWithNibName:#"PhotoPostCell" bundle:nil];
[self.listView registerNib:dqNib forCellReuseIdentifier:DQCellIdentifier];
[self.listView registerNib:simpleListNib forCellReuseIdentifier:SimpleListCellIdentifier];
[self.listView registerNib: photoPostNib forCellReuseIdentifier:ListPhotoPostIdentifier];
in my cellForRowAtIndexPath, I'm doing this(my code is fairly long so I've summarize) -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
DQCell* dqCell;
SimpleListCell* listCell;
PhotoPostCell* photoCell;
if(condition1){
listCell = [self.listView dequeueReusableCellWithIdentifier:SimpleListCellIdentifier];
//do other stuff
return listCell;
} else {
dQcell = [self.listView dequeueReusableCellWithIdentifier: DQCellIdentifier];
//do other stuff
return dQcell;
}
}
The listCell line gives me the exception..but the Dqcell line does not.
Further, in the listCell implementation I don't seem to be resizing the textView anywhere.
So what's going on? What should I be checking?
Based on the error you are getting "'NSInternalInconsistencyException', reason: 'Only run on the main thread!'", I would guess that somewhere in your code regarding a UITextView resize, you're doing something from a background thread?
Any time I'm ever doing something on a background thread, such as sending an HTTP request to a server asynchronously, and I want to display something whilst inside this background thread, such as pop up with an alertView with an error, I wrap that code in the following:
dispatch_sync(dispatch_get_main_queue(), ^{
});
This basically tells the OS to do whatever is in that block on the main thread. In the case where I pop up with an alert view while on a background thread, and when I've forgotten to do the above, the app basically locks for some period of time, seemingly broken, and randomly at a later time typically 6 or 7 seconds later, the alert pops up on screen and the app is usable again. Simple rule of thumb: don't do ANYTHING UI related on a background thread.
In your case, without looking at the entire project I wouldn't know exactly what is causing the issue. Hopefully I've given you enough information to help!
I'm developing an iPad app to help me to manage my expenses when I'm abroad.
I have a split view with the classical master and detail views. In the master there is the list of the expenses and in the detail view, guess what? The details of every expense!
When I tap on a button in the detail a new view is loaded using a modal segue with a Form Sheet. The user insert a number and if that number is bigger than a certain value the colors of the labels in the master and in the detail will change.
When I save this number I dismiss the modal view and send a NSMessage to the master in order to reload the table with the new label colors and reload the detail view selected previously.
Everything work using the iOS Simulator, but when I run the app on my iPad (iPad 2), everything freeze and I got this message:
2013-11-09 21:52:04.763 IOUinTravel[562:60b] -[NSConcreteMapTable
backdropView:willChangeToGraphicsQuality:]: unrecognized selector sent
to instance 0x18b8fb00 2013-11-09 21:52:04.767 IOUinTravel[562:60b]
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSConcreteMapTable
backdropView:willChangeToGraphicsQuality:]: unrecognized selector sent
to instance 0x18b8fb00'
* First throw call stack: (0x2df5bf4b 0x387386af 0x2df5f8e7 0x2df5e1cb 0x2dead4d8 0x30c88b43 0x306cd7b5 0x306cd6e5 0x306cd7d5
0x306cd6e5 0x306da5c3 0x306da417 0x30785f67 0x30785d83 0x3077de85
0x3077d30d 0x3077d07d 0x3077d015 0x306ceda3 0x30355c6b 0x3035147b
0x3035130d 0x30350d1f 0x30350b2f 0x306c70c3 0x2df271cd 0x2df24b71
0x2df24eb3 0x2de8fc27 0x2de8fa0b 0x32b70283 0x30733049 0x9a3d5
0x38c40ab7) libc++abi.dylib: terminating with uncaught exception of
type NSException (lldb)
I really do not know why and how to solve it.
The methods I've used are:
In the Form Sheet modal view:
- (IBAction)saveNumber:(id)sender {
// Do some stuff here
[self dismissViewControllerAnimated:YES completion:^{ [[NSNotificationCenter defaultCenter] postNotificationName:#"reloadAfterExpenseCheck" object:self];}];
}
In the main view:
- (void)reloadAfterExpenseCheck:(NSNotification *)notification
{
if ([[notification name] isEqualToString:#"reloadAfterExpenseCheck"]) {
NSLog(#"Messaggio ricevuto!");
NSLog(#"%#", self.indexPathToUpdate);
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:self.indexPathToUpdate animated:NO scrollPosition:UITableViewScrollPositionNone];
[self performSegueWithIdentifier:#"detailExpense" sender:self];
}
}
The segue #"detailExpense" works when I trigger it selecting a cell in the master table, so I do not know where is the problem... in the iOS sim it works!
Thank you for your answers.
I've solved this problem, I do not know it it is the best way but it works now.
I started to think that maybe there could be some asynchronous task going on. My Mac Mini cpu was fast enough to complete the first task, load the view and fill it with my data, the iPad cpu maybe was too slow so the view wasn't loaded... at least that is my guess.
I've simple added a NSTimer that fires the method used to load the detail view after a short time. The user do not notice the delay but it gives time to the iPad.
That's the code:
- (void)reloadAfterExpenseCheck:(NSNotification *)notification {
if ([[notification name] isEqualToString:#"reloadAfterExpenseCheck"]) {
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:self.indexPathToUpdate animated:NO scrollPosition:UITableViewScrollPositionNone];
//[self performSegueWithIdentifier:#"detailExpense" sender:self];
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(loadIt) userInfo:nil repeats:NO];
}
}
-(void)loadIt
{
[self performSegueWithIdentifier:#"detailExpense" sender:self];
}
I have a collectionview but when i tried to click the image the it showing this error ? The whole application is a tabbar application ,so all other tabs are working . except the last tab images.
iam taking images from plist for displaying it into collectionview
this is error
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI
objectAtIndex:]: index 0 beyond bounds for empty array'*** First throw call stack: (0x1e92012
0x1969e7e 0x1e47b44 0x58b91 0x56686 0x137cf 0x98f1c7 0x98f232 0x98f4da 0x9a68e5 0x9a69cb 0x9a6c76
`0x9a6d71 0x9a789b 0x9a7e93 0x9a7a88 0xd03e63 0xcf5b99 0xcf5c14 0xdaf5d9 0xdc1182 0xdc1394 0x197d705
0x9bb93c 0x9bb9ac 0x197d705 0x9bb93c 0x9bb9ac 0xb751d3 0x1e5aafe 0x1e5aa3d 0x1e387c2 0x1e37f44
0x1e37e1b 0x3c0f7e3 0x3c0f668 0x8adffc 0x287d 0x27a5) libc++abi.dylib: terminate called throwing an exception
This is the didselect method and preparesegue for passing that array to another viewcontroller
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:#"bookItem"]) {
NSDictionary *currentBook = [[_freeBooks objectForKey:#"freebook"] objectAtIndex:[[[self.collectionView indexPathsForSelectedItems] objectAtIndex:0] row]];
NSLog(#"%#", currentBook);
GMMDetailpage *detailpage = (GMMDetailpage *)[segue destinationViewController];
detailpage.bookDetails = currentBook;
NSLog(#"%#",detailpage.bookDetails);
}
}
The value of current book is printing and its fine.... but after this it executes some other system codes and then it shows exception .check image
You are doing two array accesses, so the error comes from the fact that one of the two arrays is empty.
The two arrays are
[self.collectionView indexPathsForSelectedItems]
and
[_freeBooks objectForKey:#"freebook"]
Check both the array independently and find out which one is the empty one.
I'm trying to create this application, when you press on a tablecell you get shown the ViewController, and the variable get's set in the other view controller. Although i'm getting a few errors when i press the uitablecell.
Error:
2013-04-06 22:47:25.970 iFSX Guide[1069:907] Called
2013-04-06 22:47:26.009 iFSX Guide[1069:907] -[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390
2013-04-06 22:47:26.016 iFSX Guide[1069:907] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString _isAncestorOfFirstResponder]: unrecognized selector sent to instance 0x1d562390'
*** First throw call stack:
(0x319b22a3 0x3964c97f 0x319b5e07 0x319b4531 0x3190bf68 0x33832beb 0x338a837f 0x338548fb 0x33a95619 0x338a79b9 0x338a5fe7 0x339c83ef 0xa22a5 0x3387c28d 0x338fef81 0x322c0277 0x319875df 0x31987291 0x31985f01 0x318f8ebd 0x318f8d49 0x354ba2eb 0x3380e301 0xa19d1 0x39a83b20)
libc++abi.dylib: terminate called throwing an exception
The code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)in dexPath{
NSLog(#"Called");
Aircraft = indexPath.row;
[self performSegueWithIdentifier:#"ToSections" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"ToSections"]){
AirplaneSections *sections = (AirplaneSections *)segue.destinationViewController;
sections.plane = Aircraft;
}
}
I've found out that it's an error on ViewDidLoad on the viewcontroller.
NSString *quickTemp = [NSString alloc];
switch (plane) {
case 0:
quickTemp = #"Boeing 737-800";
break;
default:
break;
}
TitleLabel.text = quickTemp;
*/
I'm doing something wrong there.
Are you using ARC? This sort of problem usually indicates there's a memory error somewhere. Basically, some code somewhere is trying to access an object that was already released. This makes everything go kaboom.
If you aren't using ARC, you should turn it on.
After that, the next thing you should do is run the static analyzer. Fix anything that comes up.
If that doesn't fix the problem, in Xcode, add a breakpoint that stops when an Objective-C exception is thrown. It should show you where exactly this problem is happening.
If that doesn't help, run your code under Instruments' and the Zombie tool. This will show you exactly where you tried to access memory that was already released.