Custom uitablecellview internal inconsistency exception - ios

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!

Related

What Does mean NSConcreteScanner setScanLocation?

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.

NSConcreteMapTable backdropView:willChangeToGraphicsQuality: ...error

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];
}

How to set the datasource of a UITableView in code

I know this question is other places on stackoverflow, but none of those solutions have worked for me. I have two tabs with table views that I want using the same datasource. The first tab's view controller is a subclass of UITableViewController. The second one is a simple UIViewController with its tableView set up in IB. I initially set up the view controller initializer to take the data source as an argument, but since that was crashing so much, I tried to simplify things by simply allocating it in my view controller. I have the Table View and datasource set up as follows:
#property (weak, nonatomic) IBOutlet UITableView *tableView; //Connected in IB
#property (strong, nonatomic) TableViewDataSource *data;
My program always crashes whenever I: [self.tableView setDataSource: data]; I tried putting that line in the viewDidLoad method, but my program still crashes. Here is my viewDidLoad method:
- (void)viewDidLoad
{
[super viewDidLoad];
data = [TableViewDataSource new]; //My data source object
NSLog(#"%#", data); //This isn't null, it says TableViewDataSource and then some address
[self.tableView setDataSource:data];
}
My first view controller works fine. It loads the data fine as well, so I don't believe I made any mistake in my datasource object. But every time I click on the second tab, the program crashes immediately. It doesn't crash if I leave out the data source assignment statement however.
Here is the crash:
2013-08-14 12:56:57.313 iPlanner[961:c07] *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:5471
2013-08-14 12:56:57.314 iPlanner[961:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack:
(0x1ca2012 0x10dfe7e 0x1ca1e78 0xb75665 0xd9c1b 0x6e40c 0xd9a7b 0xde919 0xde9cf 0xc71bb 0xd7b4b 0x742dd 0x10f36b0 0x229efc0 0x229333c 0x2293150 0x22110bc 0x2212227 0x22b4b50 0x39edf 0x1c6aafe 0x1c6aa3d 0x1c487c2 0x1c47f44 0x1c47e1b 0x1bfc7e3 0x1bfc668 0x23ffc 0x298d 0x28b5)
libc++abi.dylib: terminate called throwing an exception
(lldb)
'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
This is what is causing your app to crash. Something in the logic of your tableView:cellForRowAtIndexPath method is keeping a UITableViewCell from being returned. That log message says it all -- A UITableViewCell must be returned from tableView:cellForRowAtIndexPath:.

Objective C - -[__NSCFString _isAncestorOfFirstResponder] Error

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.

performSegueWithIdentifier crashes randomly

I have never had this problem before or heard of it happening. I am using a Master-Detail Application (splitview) for the ipad. I have a dynamic tableview for my MVC and am trying to transition each cell to a custom view controller.
Currently I only have two items in my table. When the program boots I can select either of them and it will transition to the correct view controller without any problems. But most of the time when I click on something a second time the program crashes. Sometimes it takes four or five clicks but it always eventually crashes.
Here is the code snippet:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *segueName = [self.tableObjects objectAtIndex:indexPath.row];
[self performSegueWithIdentifier:segueName sender:self];
}
tableObjects is an NSArray that I use to create the table items. If I throw a print statement in before the segue call it does print the correct segue name.
The error is always being thrown on the actual performSegueWithIdentifier call. I checked it with the debugger. The exception I keep getting is: EXC_BAD_ACCESS.
Again both of the segues work initially so I do not think it is a problem with this. Does this method sometimes get called randomly? Is there a way to double check that the method call is safe? Do I need to override performSegueWithIdentifier and do something there?
I attempted to put it into a try catch:
#try {
[self performSegueWithIdentifier:segueName sender:self];
}
#catch (NSException *exception) {
NSLog(#"%#", exception);
}
#finally {
NSLog(#"finally");
}
and it still pointed to the method call inside of the #try. It does not seem to be throwing the error like an exception?
FYI, I was running into this exact same issue, and I found the answer on another SO thread: iOS - UISplitViewController with storyboard - multiple master views and multiple detail views
Basically, the uisplitviewcontroller delegate needed to be set again when making the segue. Hope this helps someone in the future.

Resources