Here is part of my code :
LocalPosts *cell = (LocalPosts *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"LocalPosts" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
I have a .xib named LocalPosts - my code fails just there with Thread 1 - Breakpoint 1.1
I have all exceptions ON and enabled Zombies but I do not see anything printed on the console - just the (lldb).
I am running it on ios 8.0 on a device and I am using latest xcode.
I don't even know where to look at - can you help me on that?
Thanks
Related
I have created the table view using custom nib file in which i have add two images to create view like grid. When i add around 50 rows the app show me the message "memory warning" and then it will crash and Xcode show me the error "Message from debugger: Terminated due to Memory Pressure". I am testing app in iPhone 4s. it also crashes in iPhone 6. I am also using SDWebimage library for loading images. but even after comment the code of set images in "cellForRowAtIndexPath" method it crashes. Here is my code
SingleEventTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"SingleEventTableViewCell"];
if (cell == nil)
{
NSLog(#"cell allocated");
cell = [[SingleEventTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"SingleEventTableViewCell"];
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SingleEventTableViewCell"
owner:self options:nil];
cell = [nib objectAtIndex:0];
cell.selectionStyle=UITableViewCellSelectionStyleNone;
}
Can anyone suggest me how can I check memory leakage or something to resolve this issue.
Man, it's annoying how I have to keep referring back to my old xcode projects to find out how to setup a custom cell in my cellForRowAtIndexPath delegate method only because of the magnitude of methods I've seen.
What is the correct code for setting up a custom cell in the cellForRowAtIndexPath method without the use of storyboards?
I am currently doing something like this:
//This works for me btw
static NSString *simpleTableIdentifier = #"customcell";
CustomTableViewCell *customCell = (CustomTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (customCell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"CustomTableViewCell" owner:self options:nil];
customCell = [nib objectAtIndex:0];
}
Then I see other people using loadWithNibName and others that are registering their nibs in the viewDidLoad method using the registerWithNib method.
What in the world is the correct way to setup a custom cell in the delegate method?
I have also been told recently that I dont need to call the dequeueReusable.. method when I'm dealing with custom cells. Can someone please clarify the correct way to setup your cellForRowAtIndexPath delegate method once and for all for me. Without the use of story boards. I have correctly setup my custom cell view with its respective .m and .h files.
If it is CustomTableViewCell nib file exist in same UITableViewController nib your code will works fine. Otherwise you need to load nib file in cellForRowAtIndexPath:
if(cell==nil){
NSArray * nibContents = [[NSBundle mainBundle] loadNibNamed:"CustomTableViewCell" owner:self options:NULL];
NSEnumerator * nibEnumerator = [nibContents objectEnumerator];
NSObject * nibItem = nil;
while ((nibItem = [nibEnumerator nextObject]) != nil) {
if ([nibItem isKindOfClass:[UITableViewCell class]]) {
cell=(CustomTableViewCell*)nibItem;
}
}
}
I have a custom cell that has a button on it. I would like to experiment with using a long press instead.
The code that creates the cell looks like this:
CustomCell *cell = (CustomCell *)[aTableView dequeueReusableCellWithIdentifier:#"CustomCell"];
if (!cell)
{
cell = [[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil] lastObject];
}
(etc)
So I did this:
CustomCell *cell = (CustomCell *)[aTableView dequeueReusableCellWithIdentifier:#"CustomCell"];
if (!cell)
{
// cell = [[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil] lastObject];
cell = [[[NSBundle mainBundle] loadNibNamed:#"CustomCellDwellToSpeak" owner:self options:nil] lastObject];
}
Then I made a copy of the original xib. Deleted the button. Dropped an UILongPressGestureRecognizer on the cell, and created a target by control-dragging form the recognizer to the file's owner:
- (IBAction)longPress:(UILongPressGestureRecognizer *)sender;
However, once I start generating cells, I get this error:
TypOHD[41541:c07] -[UILongPressGestureRecognizer label]: unrecognized selector sent to instance 0x17d0be60
What's up with that?
I never got or found an answer to the question as such. What I did learn was that this plan is potentially flawed. Apparently mixing your won gesture recognizers in with the table view is a recipe for disaster, or at least heartbreak.
I my case, I decided to go with a fixed layout that consisted of just the number of items that would be shown anyway. In my app I was really only using a table for historical reasons anyway, and never needed to display more than 7 items.
A workaround and a hack, but it worked for me.
I have been testing the application on the device (iOS 5) while using Instruments and I found a couple of memory leaks.
This is the part of the code I'm being redirected to from Instruments (see the arrow for exact line):
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CeldaUltimasFotosViewCell *cell =
(CeldaUltimasFotosViewCell *) [self.tableView
dequeueReusableCellWithIdentifier:#"CeldaUltimasFotosViewCell"];
if (cell == nil) {
- - - - > NSArray *topLevelObjects =
[[NSBundle mainBundle]
loadNibNamed:#"CeldaUltimasFotosViewCell"
owner:nil options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
// Configure the cell...
[[cell titulo] setFont:fuente_titulo];
...
return cell;
}
As you can see, I have a custom cell which is loaded from a NIB file. There are three files for the cell (customCell.m, customCell.h, customCell.xib). The thing is that I don't know if I have to release something in the cell controller (which is now empty, no methods), since this is iOS 5 with ARC.
check out my answer here:
How can I recycle UITableViewCell objects created from a XIB?
you don't even need to use loadNibNamed any more on iOS5
Take a look at the Table View Programming and how to load cells from NIB (XIB) files.
https://developer.apple.com/library/ios/#documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW1
The first thing weird is that you are storing the cell in a local variable. You should be wiring the custom cell up to a property in the class and all you call in your code is:
[[NSBundle mainBundle] loadNibNamed:#"CeldaUltimasFotosViewCell" owner:self options:nil];
Follow the code from Loading Custom Table-View Cells From Nib Files and you can't go wrong.
I have a AQGridView , The "initialization" of the grid works great,
but when i do [gridView reloadData], it will crash with the error
2012-01-03 21:27:40.338 XXX[8454:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil key'
After a couple of tries i've tracked the error coming from AQGridView's enqueueReusableCells. Its trying to get cell.reuseIdentifier and its value is nil for some weird reason.
Here's the code for gridView:cellForItemAtindex:
- (AQGridViewCell *)gridView:(AQGridView *)aGridView cellForItemAtIndex:(NSUInteger)index{
static NSString *CellIdentifier = #"SocialCell";
SocialCell *cell = (SocialCell *) [gridView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[SocialCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier];
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:#"SocialCell" owner:nil options:nil];
for(id currentObject in topLevelObjects){
if([currentObject isKindOfClass:[SocialCell class]]){
cell = (SocialCell *)currentObject;
break;
}
}
}
As I said, first run works great, but the second run (reloading the data) , doesnt work as expected. This view includes 7 cells total so it doesn't even actually get dequeued, so i'm not sure why the value would be nil and crash.
Would appreciate any info on this :)
Thanks!