Custom UITableViewCell abandoned memory issue on Select - ios

I'm having an issue on iOS using a custom UITableView with a custom UITableViewCell. When I run the app on the Xcode Instruments I can see that there is an abandoned memory issue each time I select a cell from the custom TableView.
Please see the below a screen shot of the "Instruments".
http://i.stack.imgur.com/cKz22.png
Below is the code used to create a cell:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath2:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = [NSString stringWithFormat :#"cellID%i",indexPath.row];
customViewCell *cell = (customViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSInteger cellIndex = [indexPath row];
NSString* cellName = #"cell Name";
NSString* keyFile = #"0_48_video_1F0423D5-D2D7-466E-8D45-38C46E9B4425.mp4_1423522824.133377";
cell = [[customViewCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:cellIdentifier withKeyFile:keyFile andRicochetName:ricochetName fromTableViewController:self;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
I would appreciate any expertise on helping identifying the memory issue. Please note that the App is built on ARC.
Thanks a lot

If you just have to pass keyFile name you use this way. Make sure you have linked keyFile in interface builder
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath2:(NSIndexPath *)indexPath
{
NSString *cellIdentifier = #"cellID";
customViewCell *cell = (customViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSInteger cellIndex = [indexPath row];
NSString* cellName = #"cell Name";
NSString* keyFile = #"0_48_video_1F0423D5-D2D7-466E-8D45-38C46E9B4425.mp4_1423522824.133377";
cell.keyFile=keyFile;
return cell;
}

change the cell identifier to a static string.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath2:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = #"your tableview Cell Identifier";
customViewCell *cell = (customViewCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSString* cellName = #"cell Name";
NSString* keyFile = #"0_48_video_1F0423D5-D2D7-466E-8D45-38C46E9B4425.mp4_1423522824.133377";
cell = [[customViewCell alloc] initWithStyle:UITableViewCellSelectionStyleNone reuseIdentifier:cellIdentifier withKeyFile:keyFile andRicochetName:ricochetName fromTableViewController:self;
}
return cell;
}

Related

How to use multiple cell.textLabel.text for multiple tableview?

I am trying to create two tableviews into one single UIViewController, Here I have created two tableview with If conditional statement to operate separate process for separate tables. But the problem is I need to create separate cell.textLabel.text for separate tables. Whenever I clicked the cell I am getting first Tableview cell.textLabel.text value.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView==tableone)
{
static NSString *cellIdentifier = #"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.textLabel.text = [....]; // Here I am applying first table values
}
if (tableView==tabletwo) {
static NSString *cellIdentifier = #"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.textLabel.text = [....]; // here I am applying my values
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (tableView==tableone) {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
cellText = selectedCell.textLabel.text;
NSLog(#"%#",cellText);
}
if (tableView==tabletwo) {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
cellText = selectedCell.textLabel.text;
NSLog(#"%#",cellText);
}
}
You can give tag of the tableview in utility view.
after giving tag you can use tableview using given particular tag.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (tableView.tag == 1)
{
static NSString *cellIdentifier = #"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.textLabel.text = [....];
}
if (tableView.tag ==2) {
static NSString *cellIdentifier = #"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell.textLabel.text = [....];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (tableView.tag == 1) {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
cellText = selectedCell.textLabel.text;
NSLog(#"%#",cellText);
}
if (tableView.tag == 2) {
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
cellText = selectedCell.textLabel.text;
NSLog(#"%#",cellText);
}
}
// I think this will help you..

Table View not populating objects

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"GenusNameCell";
GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"GenusNameCell"];
cell.GenusNameLabel.text = [genusName objectAtIndex:indexPath.row];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
return cell;
}
I have a tableview with an Array of objects but when I run it. Nothing shows up. Im fairly new to xcode but Im not sure what my mistake is in the code. Can some one help me out?
If the cellForRowAtIndexPath callback is never called, it could be:
you didn't have set the dataSource of your tableview;
you didn't implement the numberOfSectionsInTableView: and/or tableView:numberOfRowsInSection: callbacks.
And if you dequeue your cell, you need to set the text outside the if branch like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"GenusNameCell";
GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"GenusNameCell"];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
cell.GenusNameLabel.text = [genusName objectAtIndex:indexPath.row];
return cell;
}
Change the code like this your code will run,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"GenusNameCell";
GenusNameCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[GenusNameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"GenusNameCell"];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
cell.GenusNameLabel.text = [[genusName objectAtIndex:indexPath.row] geniusname];
return cell;
}
geniusname is the NSString you stored the name of the person.

No Icon came up next to the name on the UITableView

Sorry if this turned out to be a stupid question~
Here is my Code in the UITableViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell....
cell.textLabel.text = [[[friendList friends] objectAtIndex:indexPath.row] profileName];
cell.imageView.image = [UIImage imageNamed:#"Zaka.jpg"];
return cell;
}
The List of Names did popped up but there's no icon next to any of it.

cellForRowIndexPath without cellidentifier ios

I do not have xib files or storyboards in my project. In this case how do I set the cell identifier? Below is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"test");
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = [self.entries objectAtIndex:indexPath.row];
return cell;
}
Try to replace you code by this (using ARC) :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.text = [self.entries objectAtIndex:indexPath.row];
return cell;
}
++
If you're just using a UITableViewCell for your table view, you can register that class in viewDidLoad like this:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:#"Cell"];
Use the same identifier in cellForRowAtIndexPath: that you use here.

Extended TableViewCell blank

I'm trying to customize a UITableViewCell, but for some reason it's showing up as blank. Is there something obvious I'm doing wrong? I've pulled the menuLabel from the storyboard as an outlet, so it's tied correctly, and the cell in the storyboard is linked to the class "MenuCell".
In my tableview controller
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"MenuCell";
[self.tableView registerClass:[MenuCell class] forCellReuseIdentifier:CellIdentifier];
MenuCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil) {
NSLog(#"creating a new cell");
cell = [[MenuCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"MenuCell"];
}
cell.menuLabel.text = #"Hello";
return cell;
}
You can use this
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"MenuCell";
MenuCell *cell = (MenuCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
UINib* customCellNib = [UINib nibWithNibName:#"MenuCell" bundle:nil];
// Register this nib file with cell identifier.
[tableView registerNib: customCellNib forCellReuseIdentifier:CellIdentifier];
cell = (MenuCell*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
// Whatever you want
retrun cell;
}
Hope this will help. happy coding :P
Use this one ....
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = #"MenuCell";
MenuCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[MenuCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell = (MenuCell *)[[[NSBundle mainBundle] loadNibNamed:#"MenuCell" owner:self options:nil] objectAtIndex:0];
}
cell.menuLabel.text = #"Hello";
return cell;
}
I Hope it will be helpful.

Resources