error when add uitableviewcontroller as subview in uiviewcontroller - iphone

i'm doing a simple app that views items from a json server
I used UISegment in one UIViewController to add different subview
- (IBAction)segmentSwitch:(id)sender {
UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;
if (selectedSegment == 0) {
instantiateViewControllerWithIdentifier:#"prestige"] animated:NO];
UIViewController *subController = [self.storyboard instantiateViewControllerWithIdentifier:#"prestige"];
[mainView addSubview:subController.view];
}
else if(selectedSegment == 1)
{
instantiateViewControllerWithIdentifier:#"latest"]];
//[self setView: [self.storyboard instantiateViewControllerWithIdentifier:#"latest"]];
//UIViewController *subController = [self.storyboard instantiateViewControllerWithIdentifier:#"latest"];
//[mainView addSubview:subController.view];
UITableViewController *tableVC =[self.storyboard instantiateViewControllerWithIdentifier:#"latest"];
[self.view addSubview:tableVC.tableView];
}
else if (selectedSegment == 2)
{
instantiateViewControllerWithIdentifier:#"contactUs"]];
UIViewController *subController = [self.storyboard instantiateViewControllerWithIdentifier:#"contactUs"];
[mainView addSubview:subController.view];
}
}
my error comes when I select select Segment 2 to view the uitableviewcontroller as subview
x code give me the following error
exc_bad_access (code=1 address=0x110ff210 on line NSDictionary *latests = [latestArray objectAtIndex:indexPath.row];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"latestCell1";
latestCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *latests = [latestArray objectAtIndex:indexPath.row];
NSString *latest_name_En = [latests objectForKey:#"title_en"];
NSString *logo1 = [latests objectForKey:#"logo"];
NSString *img1 = [latests objectForKey:#"img1"];
NSData *latestsImg1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:img1]];
NSData *latestsLogo1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:logo1]];
cell.latest_name_en1.text = latest_name_En;
dispatch_async(dispatch_get_main_queue(), ^{
cell.latest_img1.image = [UIImage imageWithData:latestsImg1];
cell.latest_logo1.image = [UIImage imageWithData:latestsLogo1];
});
return cell;
}
I'm sure the UITableViewController is working fine as I tried to run it alone and it work also tried it without custom cell and it worked also but with custon cell as a subview it gives the error above.

thanks for the help
I finally figure it out I used
[self addChildViewController:subController];
[mainView addSubview:subController.view];
to add the tableview to the viewcontroller as subview
and it worked

latestArray has not be initialized correctly.
Any time you get EXEC_BAD_ACCESS, run your code through the Zombies Instrument. This will point to any problematic code.

The objects latestsImg1 and latestsLogo1 are not being retained when they are initialized. Therefore, when the async code block executed within the dispatch_async is run those values are probably already released and no longer valid. So, when the async block executes those two pointers are point off into oblivion. I suggest either not doing those two assignments via GrandCentral dispatch, or if you must do them asynchronously, then retain them after creation and release them within the async block.
Something like:
NSData *latestsImg1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:img1]];
[latestsImg1 retain];
NSData *latestsLogo1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:logo1]];
[latestsLogo1 retain];
cell.latest_name_en1.text = latest_name_En;
dispatch_async(dispatch_get_main_queue(), ^{
cell.latest_img1.image = [UIImage imageWithData:latestsImg1];
cell.latest_logo1.image = [UIImage imageWithData:latestsLogo1];
[latestsImg1 release];
[latestLogo1 release];
});

Related

My didSelectRowAtIndexPath function causes memory leak

My first post here. Seems I have run into a bit of a memory leak problem.
I have a tab bar with two columns, one for salad and one for sushi. In each tab I also have a tableview that displays the different food choices. When the user presses one of the cells the app takes the user to a more detailview that displays a larger image and some info about the chosen food menu.
But when I run leaks I get a 98,5% leak on the following line.
[self.navigationController pushViewController: detail animated: YES];
if I release detail after this line, the app crashes.
Here is the rest of the function code:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *message = nil;
NSMutableString *image_string = nil;
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:#"detailview"];
if(tableView == SushiTable)
{
message = [sushiNames objectAtIndex:indexPath.row];
image_string = [NSMutableString stringWithString:[sushiImages objectAtIndex:indexPath.row]];
}
if(tableView == SaladTable)
{
message = [saladNames objectAtIndex:indexPath.row];
image_string = [NSMutableString stringWithString:[saladImages objectAtIndex:indexPath.row]];
}
[image_string deleteCharactersInRange: [image_string rangeOfString: #"_small"]];
NSMutableString *temp_str = [[message copy] autorelease];
NSString *final = [[[temp_str stringByReplacingOccurrencesOfString:#" " withString:#"_"]
stringByReplacingOccurrencesOfString:#"รค" withString:#"a"]
lowercaseString];
detail.food_name = message;
detail.image_name = image_string;
detail.food_info_key = final;
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.navigationController pushViewController: detail animated: YES];
detail = nil;
}
EDIT:
I saw also that in my viewDidLoad function in DetailViewController the following line has a memory leak, don't know if it's maybe related.
food_image.image = [UIImage imageNamed:image_name];
EDIT2:
Also I'm running on the simulator.
Try it.
[self.navigationController pushViewController: detail animated: YES];
[detail release];
detail = nil;
When you push an object.Now it is added into navigation stack array, Now array owner of this object
so you should need release object which you are added in an array.
Declare the detail globally and release it in dealloc:. It may work.

iPhone - Asynchronous image only displays on scroll

I've been banging my head against the wall on this one and searched far and wide for a solution to no avail:
I have a large array of data pulled from the web and I'm using Loren Brichter's ABTableViewCell to make it run smoothly by drawing everything inside of the contentView of each cell to avoid UILabels and UIImageViews slowing scrolling down.
This works great for displaying text, but I run into a problem with images because of the time it takes to download them. I can't seem to find a way to force the contentView of each cell displayed to redraw itself once the corresponding image has been downloaded. I must point out I am not drawing labels and imageViews, but just the contentView in order to save memory.
Right now the table behaves like this:
Load: text displayed, no images
Scroll up or down: images finally
show up once the cells move off screen
A sample project is here
Code:
ABTableViewCell.h
#interface ABTableViewCell : UITableViewCell
{
UIView *contentView;
}
ABTableViewCell.m
- (void)setNeedsDisplay
{
[contentView setNeedsDisplay];
[super setNeedsDisplay];
}
- (void)drawContentView:(CGRect)r
{
// subclasses implement this
}
TableCellLayout.h
#import "ABTableViewCell.h"
#interface TableCellLayout : ABTableViewCell {
}
#property (nonatomic, copy) UIImage *cellImage;
#property (nonatomic, copy) NSString *cellName;
TableCellLayout.m
#import "TableCellLayout.h"
#implementation TableCellLayout
#synthesize cellImage, cellName;
- (void)setCellName:(NSString *)s
{
cellName = [s copy];
[self setNeedsDisplay];
}
- (void)setCellImage:(UIImage *)s
{
cellImage = [s copy];
[self setNeedsDisplay];
}
- (void)drawContentView:(CGRect)r
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextFillRect(context, r);
[cellImage drawAtPoint:p];
[cellName drawAtPoint:p withFont:cellFont];
}
TableViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
TableCellLayout *cell = (TableCellLayout *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[TableCellLayout alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.cellName = [[array valueForKey:#"name"] objectAtIndex:indexPath.row];
cell.cellImage = [UIImage imageNamed:#"placeholder.png"]; // add a placeholder
NSString *imageURL = [[array valueForKey:#"imageLink"] objectAtIndex:indexPath.row];
NSURL *theURL = [NSURL URLWithString:imageURL];
if (asynchronousImageLoader == nil){
asynchronousImageLoader = [[AsynchronousImages alloc] init];
}
[asynchronousImageLoader loadImageFromURL:theURL];
cell.cellImage = asynchronousImageLoader.image;
return cell;
}
This is the final method the AsynchronousImageLoader calls once the image is prepared:
- (void)setupImage:(UIImage*)thumbnail {
self.image = thumbnail;
[self setNeedsLayout];
}
I just need the correct way to tell my visible cells to redraw themselves once the row's image has been downloaded. I imagine I should be putting something in that final method (setupImage)--but I can't seem to get it working the way it should. Thoughts? Many thanks!
Final edit: the solution
Right, so as suspected, the problem was that visible cells weren't being told to redraw and update to the downloaded image once the call was complete.
I used the help provided by the answers below to put together a solution that works well for my needs:
Added a callback in the final method that the asynchronous image downloader calls:
AsyncImageView.m
- (void)setupImage:(UIImage*)thumbnail {
self.cellImage = thumbnail;
[cell setNeedsDisplay];
}
Note: I also set a local placeholder image in the initialization of the image downloader class just to pretty things up a bit.
Then in my cellForRowAtIndexPath:
NSURL *theURL = [NSURL URLWithString:imageURL];
AsyncImageView *aSync = [[AsyncImageView alloc] initWithFrame:CGRectMake(0, 0, 20, cell.bounds.size.height)];
[aSync loadImageFromURL:theURL];
cell.cellImageView = aSync;
return cell;
There may have been one or two other tweaks, but those were the major problems here. Thanks again SO community!
Make sure that you are updating the cell image in the Main Thread. UI updates only appear if done there, which is why you only see the update when you touch & scroll.
if(cell) {
dispatch_async(dispatch_get_main_queue(), ^{
cell.cellImage = thumbnail;
[cell setNeedsDisplay];
});
}
[EDIT]
You need the cell to be the delegate of the image loader and own the async redraw mechanism.
......
AsynchronousImages *asynchronousImageLoader = [[AsynchronousImages alloc] init];
asynchronousImageLoader.delegate = cell;
[asynchronousImageLoader loadImageFromURL:theURL];
return cell;
}
And place the delegate call back code in the cell implementation.
- (void)setupImage:(UIImage*)thumbnail {
self.cellImage = thumbnail;
}
You can used the Apple TableView Lazy Loading. They have sample codes that download images asynchonously. See link below
Apple LazyTableImages
On your end in AsynchronousImages class you can add an attribute NSIndexPath and the delegate on AsynchronousImages should be change. See the code below
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
TableCellLayout *cell = (TableCellLayout *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
cell = [[TableCellLayout alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.cellName = [[array valueForKey:#"name"] objectAtIndex:indexPath.row];
cell.cellImage = [UIImage imageNamed:#"placeholder.png"]; // add a placeholder
NSString *imageURL = [[array valueForKey:#"imageLink"] objectAtIndex:indexPath.row];
NSURL *theURL = [NSURL URLWithString:imageURL];
AsynchronousImages *asynchronousImageLoader = [[AsynchronousImages alloc] init];
asynchronousImageLoader.indexPath = indexPath;
[asynchronousImageLoader loadImageFromURL:theURL];
return cell;
}
//Delegate should be
- (void)setupImage:(UIImage*)thumbnail index:(NSIndexPath*) indePath {
TableCellLayout *cell = (TableCellLayout *) [tableView cellForRowAtIndexPath:indexPath];
if(cell) {
cell.cellImage = thumbnail;
[cell setNeedsDisplay];
}
}
verify UIImage creation and setting of the UIImageView's image property happen on the main thread. there is no reason setting the image view's image should not invalidate its rect if visible.
also confirm that your loads are cancelled correctly, if you are reusing cells.
Use AsyncImageView in place of uiimageview
You can tell your tableView to reloadData... or a slightly more refined reload:
[self.tableView reloadRowsAtIndexPaths:self.tableView.indexPathsForVisibleRows withRowAnimation:UITableViewRowAnimationNone];
Edit to Add (after looking at OP's source):
I've looked through your project, and the problem is with your architecture. You're misusing AsyncImageView because you're only using it to asynchronously load your image - whereas it is designed to both load, and display the image. This is why it has no 'callback' function to let you know when the data has been retrieved.
You would be better off replacing your CellLayout's image property with a UIImageView property instead. (Note that UIImageView is more efficient at drawing than image drawAtPoint anyway).
So:
Change your CellLayout class to use an UIImageView property instead of UIImage
Change your cellForRowAtIndexPath to set the AsyncImageView as a property directly on your Cell.
If you want to support placeholders, that should be added to your AsyncImageView class - so that it knows what to display while downloading the content.
cellForRowAtIndexPath:
NSURL *theURL = [NSURL URLWithString:imageURL];
AsyncImageView *aSync = [[AsyncImageView alloc] initWithFrame:CGRectMake(0, 0, 20, cell.bounds.size.height)];
[aSync loadImageFromURL:theURL];
cell.cellImageView = aSync;
return cell;
CellLayout.h
#property (nonatomic, strong) UIImageView *cellImageView;
CellLayout.m
- (void)setCellImageView:(UIImageView *)s
{
[cellImageView removeFromSuperview];
cellImageView = s;
[self addSubview:cellImageView];
}

TouchJSON How to make a table populated with json clickable?

I am a total newbie on iOS development. After numerous tries; with lots of sample codes I managed to parse a json string from my server and able to display the results in a dynamic tableview. My problem is I cannot make the cells clickable so they would pass the id and the label to another view where another json parse will be performed to display the details of the row.
Below is my code:
#import "jsonviewcontroller.h"
#import "CJSONDeserializer.h"
#import "Otel_ItemViewController.h"
#implementation jsonviewcontroller
#synthesize tableview;
#synthesize rows;
- (void)dealloc {
[rows release];
[tableview release];
[super dealloc];
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [rows count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
NSDictionary *dict = [rows objectAtIndex: indexPath.row];
cell.textLabel.text = [dict objectForKey:#"C_NAME"];
cell.detailTextLabel.text = [dict objectForKey:#"CAT_ID"];
return cell;
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:#"http://zskript.net/categories.php"];
NSString *jsonreturn = [[NSString alloc] initWithContentsOfURL:url];
NSLog(jsonreturn); // Look at the console and you can see what the restults are
NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding];
NSError *error = nil;
// In "real" code you should surround this with try and catch
NSDictionary * dict = [[[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error] retain];
if (dict)
{
rows = [dict objectForKey:#"users"];
}
NSLog(#"Array: %#",rows);
[jsonreturn release];
}
// Do some customisation of our new view when a table item has been selected
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Make sure we're referring to the correct segue
if ([[segue identifier] isEqualToString:#"ShowSelectedMovie"]) {
// Get reference to the destination view controller
Otel_ItemViewController *vc = [segue destinationViewController];
// get the selected index
NSInteger selectedIndex = [[self.tableview indexPathForSelectedRow] row];
// Pass the name and index of our film
[vc setSelectedItem:[NSString stringWithFormat:#"%#", [rows objectAtIndex:selectedIndex]]];
[vc setSelectedIndex:selectedIndex];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
#end
And below is the view that will display the detail:
#import "Otel_ItemViewController.h"
#implementation Otel_ItemViewController
#synthesize selectedIndex, selectedItem;
- (void)viewDidLoad
{
[super viewDidLoad];
[outputLabel setText:selectedItem];
[outputText setText:selectedItem];
[outputImage setImage:[UIImage imageNamed:[NSString stringWithFormat:#"%d.jpg", selectedIndex]]];
}
#end
Currently, when I click the cells in the table, Although I have set it to push to the next view, nothing happens. Would someone please advise?
Here is the updated code.
My root view controller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dict = [rows objectAtIndex: indexPath.row];
DetailViewController *controller = [[DetailViewController alloc] init];
controller.CATNAME = [dict objectForKey:#"C_NAME"];
controller.CATNUMBER = [dict objectForKey:#"CAT_ID"];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
And here is DetailViewController.h:
#interface DetailViewController : UIViewController {
NSString *CATNAME;
NSInteger CATNUMBER;
IBOutlet UILabel *labelId;
IBOutlet UILabel *LabelName;
}
#property (nonatomic) NSInteger CATNUMBER;
#property (nonatomic, retain) NSString *CATNAME;
#end
And DetailViewController.m:
#import "DetailViewController.h"
#implementation DetailViewController
#synthesize CATNAME, CATNUMBER;
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void) viewDidLoad
{
LabelName.Text = CATNAME;
labelId = CATNUMBER;
// [LabelName setText:CATNAME];
// [labelId setText:CATNUMBER];
}
You have to implement this method
EDIT: Loading a new view
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dict = [rows objectAtIndex: indexPath.row];
MyNewViewController *controller = [[MyNewViewController alloc] init];
controller.C_NAME = [dict objectForKey:#"C_NAME"];
controller.CAT_ID = [dict objectForKey:#"CAT_ID"];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
}
In the code above I assume you are using a navigation controller (which is the easiest way to do what you want to be doing). Also I am assuming you have a class that inherits from UIViewController that you want to have displayed. I am also assuming that this class which I called MyNewViewController in my example has two members and properties called C_NAME and CAT_ID respectively.
- (void) viewDidLoad
{
labelName.Text = C_NAME;
labelId = CAT_ID
}
The above my be incorrect as I am doing it out of memory. But the principal stays the same, if you passed the variables correctly it should work, you can have a look at my blog it still needs some work done on it, but it has a nice beginners post and shows how to edit the text of the label. In the code above I am assuming your view contains two labels labelName and labelId respectfully.
In there you have access to what cell was selected and you can then define what needs to happen.

Reloading UITableView

I've read some of the other posts but haven't found the right solution that seems to work in my case. I've got a UITableViewController class that is instantiated from the Main App Delegate and it controls other views that get pushed into the UINavigationController instance created from the App Delegate.
On the UINavigationToolBar I have a UISegmentedControl button that is split in two pieces, Factory Loads and User Loads. I have an action method attached to the SegmentedControl to detect when the button is pressed and that method is inside the UIViewController Class. My goal is to have the view reload with the contents of a new dictionary that is constructed from a plist file in the app bundle. I have the dictionary loaded, and the keys to be displayed set up in the respective data formats, but when I try to reload the UITableView, it crashes.
This is the last code I tried to get to work inside my action method, but it still doesn't function as intended.
- (void) action:(id)sender {
UISegmentedControl *segment = (UISegmentedControl *) sender;
if ([segment selectedSegmentIndex] == 1)
{
NSLog(#"User Load Selected");
NSString *userLoadFilePath = [[NSBundle mainBundle] pathForResource:#"UserLoads" ofType:#"plist"];
NSDictionary *userLoadDictionary = [[NSDictionary alloc] initWithContentsOfFile:userLoadFilePath];
NSArray *allKeys = [userLoadDictionary allKeys];
keys = allKeys;
dictionary = userLoadDictionary;
[[self tableView] reloadData];
}
else if ([segment selectedSegmentIndex] == 0)
{
NSLog(#"Factory Load Selected");
NSString *factoryLoadFilePath = [[NSBundle mainBundle] pathForResource:#"AlliantPowder" ofType:#"plist"];
NSDictionary *factoryLoadDictionary = [[NSDictionary alloc] initWithContentsOfFile:factoryLoadFilePath];
NSArray *allKeys = [factoryLoadDictionary allKeys];
keys = allKeys;
[[self tableView] reloadData];
}
}
I'm calling [[self tableView] reloadData] in an attempt to retrieve the actual table contained within the UIViewController to try to get the table to reload, but no luck. Any help is appreciated, and if more code is needed please ask. Thanks!
Andrew
------- Edit -----------
Here is the new code in reference to Chip's ideas. The issue is still not resolved and the app still crashes.
- (void) action:(id)sender {
// Create an instance of UISegmentedControl and set it as the sending event.
UISegmentedControl *segment = (UISegmentedControl *) sender;
// Detect which button was pressed and load a new dictionary appropriately
// Checking if userLoads was selected
if ([segment selectedSegmentIndex] == 1)
{
NSLog(#"User Load Selected");
keys = userKeys;
[[self tableView] reloadData];
}
// Checking if factoryLoads was selected
else if ([segment selectedSegmentIndex] == 0)
{
NSLog(#"Factory Load Selected");
keys = [dictionary allKeys];
[[self tableView] reloadData];
}
[segment release];
}
I would pre-load the dictionaries and hold them as ivars in the controller class.
I am betting that the loading of the dictionary contents is not complete, so you are in effect calling reloadData while the data is changing which is causing your crash.
Also, the read is an expensive option and you are loading each time the segementControl changes state.

some time can't access NSmanagedObject returned form fetchResultController

I have been struggling several days because of some weird overreleased.
My tableView is little bit different type so can't use NSFetchControllerDelegate.
Actually three thumbnail views in each row which can toucable.
So can't use didSelectRowAtIndexPath.
The problem is after execution patch. The first access to NSManagedObject returned from
fetchedResultController objectAt indexPath works ... but second try make access to deallocated object which mean is object is already overreleased.
But the more make me crazy is exact same function in TableViewCellForRowAtIndexPath is work always.
#pragma mark AlbumListViewCellSelectionDelegate ==> my custom delegate method****
- (void)albumContentsTableViewCell:(AlbumLibViewCell *)cell
selectedPhotoAtIndexType:(NSUInteger)index {
//[self fetch];
NSLog(#"select !!!! %i",index);
lastSelectedRow=cell.rowNumber;
//[selectedAssets addObject:[assets objectAtIndex:(lastSelectedRow * imageNoPerRow) + index]];
int selectId =(lastSelectedRow * imageNoPerRow) + index;
if(albumCount >=(selectId+1)){
AlbumTag * album = (AlbumTag *)[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:selectId inSection:0]] ;
//scrollView
AutoScrollViewController *detailViewController =[[AutoScrollViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed=YES;
detailViewController.selectedMoments = [album.moments allObjects];==> first work but overrelease every second try
detailViewController.initPhotoNumber = 0;
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
same function but every time no problem
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = #"AlbumLibViewCell";
AlbumLibViewCell *cell = (AlbumLibViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"AlbumLibViewCell" owner:self options:nil];
cell = tmpCell;
tmpCell = nil;
}
cell.backgroundColor =[UIColor blackColor];
cell.rowNumber = indexPath.row;
cell.selectionDelegate = self;
// Configure the cell...
NSUInteger firstPhotoInCell = indexPath.row * imageNoPerRow;
NSUInteger lastPhotoInCell = firstPhotoInCell + imageNoPerRow;
if (albumCount <= firstPhotoInCell) {
NSLog(#"We are out of range, asking to start with photo %d but we only have %d", firstPhotoInCell, albumCount);
return nil;
}
NSUInteger currentPhotoIndex = 0;
NSUInteger lastPhotoIndex = MIN(lastPhotoInCell, albumCount);
for (firstPhotoInCell ; firstPhotoInCell + currentPhotoIndex < lastPhotoIndex ; currentPhotoIndex++) {
AlbumTag *albumCell = (AlbumTag *)[fetchedResultsController objectAtIndexPath:[NSIndexPath indexPathForRow:firstPhotoInCell + currentPhotoIndex inSection:0]];
UIImage *thumbnail = albumCell.rpeMomentThumbnail;
NSArray *moments = [albumCell.moments allObjects]; ===> every time works fine
Any idea for this situation might be help
appreciate in advance all.
Seems like objects being passed into detailViewController are being released but not retained. You should turn on NSZombies to debug this. If that doesn't work you can track your allocation history using the ObjectAlloc instrument in Instruments.