Getting Exception while scrolling the table view - iphone

I have table view with customize cell . I have 100 images on table view . When i run the application all images are get loaded on the table view .I can also scroll from top to bottom till 100th element. But while scrolling from bottom to to got the following exception at the somewhere at the middle at the fixed element :
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/bc/Library/Application Support/iPhone Simulator/5.1/Applications/B5090983-ACC0-4428-9741-255B7D72F674/ImageCaching.app> (loaded)' with name 'CustomCell''
*** First throw call stack:
(0x159b022 0x172ccd6 0x1543a48 0x15439b9 0x2fd638 0x2feeb7 0x33b7 0x176c54 0x1773ce 0x162c04 0x1716f1 0x11ad42 0x159ce42 0x1f53679 0x1f5d579 0x1ee24f7 0x1ee43f6 0x1f7f1ce 0x1f7f003 0x156f936 0x156f3d7 0x14d2790 0x14d1d84 0x14d1c9b 0x14847d8 0x148488a 0xdc626 0x298d 0x28f5)
terminate called throwing an exception(lldb)
i have following code for table view:
NSArray *objects=[[NSBundle mainBundle]loadNibNamed:#"CustomCell" owner:self options:nil];
NSLog(#"count =%d" ,[objects count]);
CustomCell *cell=[objects objectAtIndex:0];
Resource *r=[setUpArray objectAtIndex:indexPath.row];
cell.cellImage.image=[UIImage imageWithContentsOfFile:[library getResource:r.key]];
I am loading nib name of customize cell accurately.Please give me some solution.

Related

Code working on iPhone 5, not on iPod touch 4

I'm testing my application on different devices. The app works fine on my iPhone 5, however, when I test it on my iPod touch 4g, I get this eror:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** [__NSArrayMinsertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x33f252a3 0x3bba397f 0x33e6f8d9 0x51e25 0x35e180c5 0x35e1814d 0x35e180c5 0x35e18077 0x35e18055 0x35e1790b 0x35e17e01 0x35d405f1 0x35d2d801 0x35d2d11b 0x37a1f5a3 0x37a1f1d3 0x33efa173 0x33efa117 0x33ef8f99 0x33e6bebd 0x33e6bd49 0x37a1e2eb 0x35d81301 0x4fc8d 0x3bfdab20)
libc++abi.dylib: terminate called throwing an exception
The code that's crashing is this one:
/********/
NSMutableArray *titulosCampoTextArray = [[NSMutableArray alloc] init];
for (int i = 0; i < campos.count; i++) {
SignupCell *cell = (SignupCell*)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
[titulosCampoTextArray addObject:cell.textField.text];
}
/********/
I'm using custom prototype cells (SignupCell.h), on a UITableView inside a UIView.
Can't find the error, or how to fix it.
EDIT: Both devices are running iOS 6.1.3, and I'm using Xcode 4.6.1.
UITableView's -cellForRowAtIndexPath: method returns nil if the cell isn't visible on screen when you call it.
My guess is that on the iPhone 5 your table can display all rows at once, while on the shorter iPod touch, the last one or two cells aren't visible and -cellForRowAtIndexPath: thus returns nil, which makes your app crash.
You shouldn't rely on -cellForRowAtIndexPath to request model data! Your view controller is responsible for the data, not the table view.
Use the same way to access the model data like you do for setting the table view cells' text in the -tableView:cellForRowAtIndexPath: data source method of your view controller.
Just do this:
NSMutableArray *titulosCampoTextArray = [[NSMutableArray alloc] init];
for (int i = 0; i < campos.count; i++) {
SignupCell *cell = (SignupCell*)[self.tableView
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
if (cell.textField.text) {
[titulosCampoTextArray addObject:cell.textField.text];
}
}
I don't know why you apparently can add nil on an iPhone 5 but not on an iPod. It may be that for some other reason you just never happen to have a nil value for cell.textField.text when your app is running on the iPhone 5.

UITableView error "Could not load NIB in bundle:" for custom cell

When I try with the following coding for custom cell, Its showing error.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpletablcellCell";
SimpletablcellCell *cell = (SimpletablcellCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpletablcellCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.nameLabel.text = [ar objectAtIndex:indexPath.row];
cell.thumbnailImageView.image = [UIImage imageNamed:[ar1 objectAtIndex:indexPath.row]];
cell.prepTimeLabel.text = [ar objectAtIndex:indexPath.row];
return cell;
}
Error msg
'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/apple/Library/Application Support/iPhone Simulator/6.0/Applications/FE02B3A1-C40C-4FAC-BBA6-B245350F3754/SImpleTab.app> (loaded)' with name 'SimpletablcellCell''
*** First throw call stack:
(0x1c8f012 0x10cce7e 0x1c8edeb 0x22ffac 0x23198d 0x3418 0xcef4b 0xcf01f 0xb780b 0xc819b 0x6492d 0x10e06b0 0x228bfc0 0x228033c 0x228beaf 0x1038cd 0x4c1a6 0x4acbf 0x4abd9 0x49e34 0x49c6e 0x4aa29 0x4d922 0xf7fec 0x44bc4 0x44dbf 0x44f55 0x4df67 0x2d40 0x117b7 0x11da7 0x12fab 0x24315 0x2524b 0x16cf8 0x1beadf9 0x1beaad0 0x1c04bf5 0x1c04962 0x1c35bb6 0x1c34f44 0x1c34e1b 0x127da 0x1465c 0x29fd 0x2925)
libc++abi.dylib: terminate called throwing an exception
Please check, what is wrong with this code?
Does a .nib / .xib exist in your project named SimpletablcellCell? You might have a typo in the name, please check carefully.
Make sure the file is part of your target. You can check this by opening the right-side menu in Xcode. Example:
If the cell exists, is it being copied in the build process? Check the "Copy bundle resources" phase in your project target build settings and make sure it is being copied. If not, add the file manually to this phase.
I had this problem when using Cocoapods for a private pod library of mine.
I had incorrectly included my xib files in s.source_files like so
s.source_files = 'MyLibrary/**/*.{h,m,xib}' //DOES NOT WORK
The solution was to use the resources attribute:
s.resources = 'MyLibrary/**/*.{xib}' //PROBLEM SOLVED
s.source_files = 'MyLibrary/**/*.{h,m}'
...
Then there is the problem that occurs if your podspec is looking for the xib as specified by s.resources above, but the xib is not in that path.
Once I mistakingly added a xib to my root project directory (where your AppDelegate is) and so Cocoapods would not copy it to any clients using the pod.
I fixed this by either changing the s.resources path or moving the xib so that it would be in the s.resources path.
If you are registering the nib using:
let nib: UINib = UINib(nibName: "myNib", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "myCell")
make sure it is done in the viewDidLoad() function. I had placed it in the init() function and received this error. Once moved to viewDidLoad(), it worked well.
This error can occur when you rename some files outside XCode. To solve it you can just remove the files from your project (Right Click - Delete and "Remove Reference") You re-import the files in your project and everything will be ok !
Make sure your custom cell is added to the target you are building. Register that cell without fail.
There should be no IBOutlet errors in xib. Also, connect the view to the file owner.
The common error could be the name of the nib you are loading is incorrect.

UIImageview set image crash

I'm setting image to a UIImageView using in the below code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
for(int i=0;i<[radioButtons count];i++){
[[radioButtons objectAtIndex:i] setImage:[UIImage imageNamed:#"checkbox_unchecked.png"]];
}
UIImageView *imageViews=(UIImageView *)[self.view viewWithTag:indexPath.row];
[imageViews setImage:[UIImage imageNamed:#"checkbox_checked.png"]];
}
So on clicking any tableview cell the images gets sets. But once if I click on objectatindex:0
then the app crashes. I'm unable to fix this.
Below is the crash log:
2012-08-20 16:25:36.321 EventApp[2422:12503] -[UIView setImage:]: unrecognized selector sent to instance 0x79642b0
2012-08-20 16:25:36.321 EventApp[2422:12503] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0x79642b0'
*** First throw call stack:
(0x1de3022 0x1c03cd6 0x1de4cbd 0x1d49ed0 0x1d49cb2 0x7a98c 0xc615c5 0xc617fa 0x14f685d 0x1db7936 0x1db73d7 0x1d1a790 0x1d19d84 0x1d19c9b 0x1be57d8 0x1be588a 0xbd0626 0x380a2 0x23b5)
terminate called throwing an exception(lldb)
I think you are not getting UIImageView Object,you are getting uiview types object that's why it crashes. you should try to Define another tag property like 999+indexPath.row. Got it somewhere you define the tag=0 or IB automatically takes tag=0 to all object so it taking uiview with tag 0 not uiimageView
this means that you are sending message -(void)setImage to UIView, not to UIImageView. Make sure that view with tag indexPath.row and all radioButtons in array are actually UIImageView

Which class must I extend?

(I am developing an app that presents chat messages in a table. But, this chat can't be started by the user, when the user receives a message the chat view opens. So, I made this code:
- (void) newMessageReceived:(NSMutableDictionary *)message
{
General *general = [General sharedManager];
NSString *firstmessage=[message objectForKey:#"msg"];
NSString *from=[message objectForKey:#"sender"];
NSArray *listItems = [from componentsSeparatedByString:#"#"];
NSString *fromsplit=[listItems objectAtIndex:0];
general.firstmess=firstmessage;
general.firstfrom=fromsplit;
NSLog(#"Mensaje recibido: %# de %#", [message objectForKey:#"msg"], fromsplit);
ChatViewController *cvc=[[ChatViewController alloc]initWithNibName:#"Chat" bundle:nil];
[[self navigationController]pushViewController:cvc animated:YES];
}
Everything is ok, until here. The ChatViewController extends UITableViewController. But, when a message is received i get the following exception:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "Chat" nib but didn't get a UITableView.
Then, i try to change the class extended to UIViewController (did this to check that the program enters the numberOfRowsInSection method) and then i receive:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ChatViewController setTableViewStyle:]: unrecognized selector sent to instance 0x9863200'
I think that solving the first exception would fix my problem. Any help?
Thank you.
In the second exception i think you have called [self setTableViewStyle:] method, while
you have made it UIViewController.
So try to call this method by tableViewOutlet.
[tableView setTableViewStyle:];
Hope this will help you
Solved it. i click the .xib file, under "objects", clicked "View". And then, in the Identity Inspector (the third one, starting from the left), in Custom Class, set it to UITableView. It was simply "View" before. And then, everything worked fine.

how to solve unrecognized selector sent to instance?

I have a uitableview 'A' which has cells, on clicking one of the cell, it needs to push another table view 'B'. and now when a cell is clicked in 'B', its needs to open a simple view.
I have managed to display both the tables in two different views. but when a cell is clicked in the menu B. it hangs and shows the below message
> unrecognized selector sent to > instance
could someone please tell me how do i solve this.thanks
Please find below my code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger row = [indexPath row];
NSLog(#"entering the if loop libdecripviewcontoller");
if(self.libraryDescripViewController == nil){
NSLog(#"its creating new instance of libdecripviewcontoller");
LibraryDescripViewController *aLib = [[LibraryDescripViewController alloc] initWithNibName:#"LibraryDescripView" bundle:nil];
self.libraryDescripViewController = aLib;
[aLib release];
}
libraryDescripViewController.title = [NSString stringWithFormat:#"%#",[libraryMenu objectAtIndex:row]];
ULS1AppDelegate *delegate = [[UIApplication sharedApplication] delegate ];
[delegate.searchLibNavController pushViewController:libraryDescripViewController animated:YES];
}
Please find the output below
2010-06-27 20:13:15.521 ULS1[1020:207]
entering the if loop
libdecripviewcontoller 2010-06-27
20:13:15.533 ULS1[1020:207] its
creating new instance of
libdecripviewcontoller 2010-06-27
20:13:15.541 ULS1[1020:207] *
-[LibraryMenuTabViewController setLibraryDescripViewController:]:
unrecognized selector sent to instance
0x3c2ec70 2010-06-27 20:13:15.554
ULS1[1020:207] * Terminating app due
to uncaught exception
'NSInvalidArgumentException', reason:
'*** -[LibraryMenuTabViewController
setLibraryDescripViewController:]:
unrecognized selector sent to instance
0x3c2ec70' 2010-06-27 20:13:15.558
ULS1[1020:207] Stack: ( 29303899,
2512004361, 29685819, 29255286,
29107906, 14755, 3050054, 3033220,
287146, 29088448, 29084744, 37393941,
37394138, 2777007, 11184, 11038 )
You can get more information about where the error is happening by opening your debugger window, clicking on "Show Breakpoints", and setting the following two breakpoints:
[NSException raise]
objc_exception_throw
Now when your app is about to crash, the debugger will usually show you exactly what line of code is causing the problem.
For this reason, it's good practice to have these breakpoints on every app you are developing.
It seems that you are calling "self.libraryDescripViewController = aLib" which is another way of writing [self setLibraryDescripViewController:alib].
The most likely cause of this would be in that you haven't declared the method setLibraryDescripViewController in your class.
Hope this helps.
There is way too little information here to diagnose exactly whats causing this, but one thing is certain. The method you are sending to the object is not defined for that object. Please post the code thats causing the error and the .h and .m files for the simple view you are talking about.
You probably need to set the class of the view controller in IB to LibraryDescripViewController. Double click the LibraryDescripViewController.xib file in xcode and when IB opens, in the identity view of the file's owner set the class to LibraryDescripViewController