CellForRowAtIndex method not get invoked - ios4

I am fetching some data across the web and want to display it in a table view.
I am fetching this data as soon as the view will appear, using the -(void)viewWillAppear:(BOOL)animated method.
I am performing this fetching process in a background thread and want to display this data in my table view.
So now my problem is that the cellForRowIndexPath method is not get called.
What is the solution for this, so that after fetching the data it gets displayed in the table view?

First check your TableView links with a delegate and data source, and then try again.
And every time when you come back to your view, write:
-(void)viewWillAppear:(BOOL)animated
{
[self.tableView reloadData];
}

to reload table you should call reloadData. Also, - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath will only get called if you set dataSource for your UITableView

Related

Use core data to send email with string

I have set up a core data model and I would like the ability to be able to tap on an entry and have an blank email pop up with the core data contents included. here is my code for saving the data-
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:#"Device" inManagedObjectContext:context];
NSNumber *timetickNumber = [NSNumber numberWithInt:timeTick];
NSString *versionString = [NSString stringWithFormat:#"Minutes of %#", self.versionTextField.text];
[newDevice setValue:timetickNumber forKey:#"name"];
[newDevice setValue:versionString forKey:#"version"];
[newDevice setValue:self.companyTextField.text forKey:#"company"];
Thanks in advance!
You can't click (or tap) on a Core Data object, because they do not have any UI and do not respond to UI events. The general flow you want is probably something like:
Figure out what UI element should trigger the email action-- a button, or a table row, or whatever UI element you're using.
In the handler method for taps on that element, create the MFMailComposeViewController. Where this happens depends on what UI element you're using. If your UI element is a button, this happens in whatever method your button calls when tapped. If the UI element is a table row, you probably want to use tableView:didSelectRowAtIndexPath: in your table view's delegate.
In that same method, get a reference to the managed object you want to send. If you fetched it (or created it) earlier, you might already have an instance var that points to it. If not, you may need to fetch it here.
Before displaying the MFMailComposeViewController, configure either the message body (via setMessageBody:isHTML:) or the attachment (via addAttachmentData:mimeType:fileName:) to contain the data from your managed object's data
Display the mail compose view to the user.

UITableView not loading data the second time

I have a UITableView and I call reloadData in the viewWillAppear method
- (void)viewWillAppear:(BOOL)animated {
[tableView reloadData];
}
However, the second time my view appears, neither numberOfRowsInSelection nor cellForRowAtIndexPath are called
What could I be doing wrong?
I am seeing the same problem and yes, using a breakpoint I have already confirmed that viewWillAppear is called and reloadData executed - but cellForRowAtIndexPath is never called and the table contains stale data.
New information: I tried creating a new class/nib, this time using a UITableViewController instead of a UIViewController and implementing the delegate & datasource interfaces manually. This works as expected - cellForRowAtIndexPath is called and the table is updated. There must be something else UITableViewController does for me that I need to implement in my version, but I don't know what it is....
Solved! My issue, anyhow. I had wired up the datasource and controller connections, but hadn't connected the tableView outlet in my class to the table in the UI builder. smacks forehead. Mine works now, hope this helps!

Core Data: delay calling endUpdates till viewWillAppear

I have a Core Data app with a tab-bar controller that displays 2 view controllers. If I add something in the first tab's view controller, it should display in the 2nd tab's VC. Both VCs are based off a NSFetchedResultsController which is based off the same entity; the only difference is that one has a predicate and the 2nd VC doesn't.
This works fine for the normal template, and when data is added from the 1st VC, it gets updated instantly in the 2nd tab using controllerWillChangeContent and controllerDidChangeContent. The problem is that if the user adds or deletes any rows in the 1st VC, when the user comes to the 2nd tab they don't see the rows animatedly inserted or deleted... everything's already there.
What I would like to do, in the 2nd tab's VC, is delay calling the [self.tableView endUpdates] (which causes the animated inserting/deleting of rows in the table) till the user actually goes to that tab, in that VC's viewWillAppear. I've tried this, but doesn't seem to work:
- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
{
tableviewUpdates = TRUE;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (tableviewUpdates) {
tableviewUpdates = FALSE;
[self.tableView endUpdates];
}
}
This works if adding one row at a time and then switching to the 2nd tab, but not if I add multiple rows in the 1st tab and then switch.
Any help would be appreciated.
You're working against the purpose of the NSFetchedResultsController which is to make updating the tableview automatic and effortless.
I'm pretty sure, however, that if you override all the FRC delegate methods you can block all the automatic updates.
You might want to rethink this design. Are users really going to expect to see changes in one view reenacted in a second? Will they understand they are watching a rewind of the previous changes or will they intuitively think that the app is doing something to their data on its own?
The standard UI grammar teaches users to expect that one change animates once and then subsequently just shows up in a standard display. I would suggest you test this design with naive users carefully before deploying such a non-standard interface.

tableview methods are been called only Once in Objective C on iphones?

i have tableview.In method 'viewWillAppear',it calls a function and function data is stored in an array named 'list'.Now in the method 'numberOfRowsInSection' method it returns the list count...and in another method 'cellForRowAtInexPath' it displays data in cell...now when the view is pushed to the above view using pushViewnavigationcontroller,function is called in viewwillappear and data is shown in tableview..now when i come back to previous view and move to tableview view again...viewWillAppear method is called(i checked using NSLog)...but tableview displays the same previous data..that means methods numberOfRowsInSection,cellForRowAtIndexPath are called only Once at first click..why is it so??and what can be done to load the tableview again and again with changing values of the data..??
I found the solution by myself. Just use [tableview reloadData] in method viewWillAppear.

SearchDisplayController & Coredata Search locks the application while loading, what can i do?

I am building an application with coredata. Its nearly finished but i have a problem.
I want to put a search section on my application. I did it now and it is working, but there is something weird and i could not solve.
When clicked on the search button, i am preparing my Predicates and search my database, and show the data on tableview.
There are about 18000 entries on my database and when searching some words, the application is getting locked for a while, after the proccess end application shows my tableview as i want.
I want to put an activity indicator or something like that while this long progress is being done but i cant, because the application is being locked in that time.
What can i do in this case? I could not find any solution.
Thanks for your helps.
Regards.
you should start search in a new thread. while the main thread will show your indicator view (you can do visual stuff only in a main thread).
//make UIIndicatorView visible and start a new thread
[NSThread detachNewThreadSelector:#selector(doSearch) toTarget:self withObject:nil];
-(void) doSearch{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//do search stuff;
....
// tell your main thread that search is done
[self performSelectorOnMainThread:#selector(searchDone) withObject:nil waitUntilDone:NO];
[pool release]; }
-(void) searchDone{ //hide UIIndicator view
}

Resources