NSUrlConnection with table view and search display controller - iphone

I am writing an iPhone app which gets data from a mysql database. I am trying to use a search display controller to search the database as the user types input into the search bar, but the problem I am having is that uitableview methods are called before the nsurlconnection methods.
My current coding logic is as follows;
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
//code to start connection
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
//populate array of search results
//Load data into search results
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
Does anyone know how to make this work or know of another method of doing this? If something is unclear or you need some more information please let me know.
Thank you for your help.

Are you calling [tableView reloadData] after populating search results?

Related

what is the difference between didselectrowindexpath and willselectrowindexpath in iphone?

Give an explanation about difference between UITableView delegate methods:
didDeselectRowAtIndexPath:
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
and
willSelectRowAtIndexPath
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
willSelectRowAtIndexPath message is sent to the UITableView Delegate after the user lifts their finger from a touch of a particular row and before didSelectRowAtIndexPath.
willSelectRowAtIndexPath allows you to either confirm that the particular row can be selected, by returning the indexPath, or select a different row by providing an alternate indexPath.
Good luck
T
the code written in
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath(NSIndexPath*)indexPath
method is run after selected the row and the code is written in
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath(NSIndexPath*)indexPath
run just before the row selected.
they are same as
- (void)viewDidAppear:(BOOL)animated and - (void)viewWillAppear:(BOOL)animated
let me know if you have any confusion now.

is there any if statement for showing/hiding a method in objC?

i use same uiviewcontroller's instance in different tabs.
there is a uitableview in viewcontroller.
in firstviewController instance, i dont wanna edit the uitableview.
in the second one i use edit mode for tableview.
thats why i want to show or hide this method:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
is it possible to make an if statement like this:
#if (editingOK)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
....some codes
}
#endif
editing OK is a BOOL property.
if you ask why i want it, because if the user swipes on the cell, it display Delete button.
i just want it if my editingOK=YES.
The #if/#endif syntax is used for conditional compilation: it lets you modify your program at compile time based on build configuration. Read about the "C preprocessor" to learn more.
If you are, as you say, using the same object instance as the delegate of different UITableViews, you must have some way to determine which table you are dealing with.
What you need to do is implement an additional method:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
That method is called when the user swipes the cell, and you can decide if a delete button should appear or not, then return the appropriate UITableViewCellEditingStyle constant.
Isn't editability controlled by calling the setEditing method of the UITableViewController? So you could set that depending on whether or not you want to enable editing, w/o this #ifdef ugliness.

Rearrange Uitableview row

I have an iPhone application that has a user preference page where the user can rearrange the uitableview rows just like the iPhone built in weather forecast app's settings page. Now my problem is after the user in done with rearranging, I need to save the data in database in rearranged order. But I'm not been able to read the data from the uitableview.
How can I read the rearranged data from the uitableview?
Looking for your valuable response
Thanks in advance
Joy
You do not read the rearraged order at the end of the editing, UITableView tells it's dataSource what is being changed while the editing takes place. It does so using the messages:
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath;
- (void)tableView:(UITableView *)tableView
moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath;
You would implement your datasource, so that it records this changes and can store them when the editing is finished.
Another not recommend way would be the to enumerate your tableView cell's using
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath;
Then figure out with dataEntity is represented by this cell, and reconstruct the underlying data.
The last approach is only for completeness, please use the first.

tableview has nothing?

my tableview has the following method.i have done everything perfectly...numberOfRowsInSection returns 10.....the following method will not be called....it shows nothing......
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
There are lots of places you could have gone wrong...and if you post some code you're much more likely to get a solution but some possibilities.
Have you also implemented
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
Have you set the tableview's datasource and delegate to your controller? (Either programatically or via interface builder outlets)
Does your controller declare the UITable view datasource and delegate protocols in it's header OR subclass UITableViewController?
Without you providing more info it's pretty hard to give a solution.

Can we use the ABPeoplePicker view for something other than selecting a single contact?

I'm attempting to implement a 'better' address book for IPhone and I just want to make additions to Apple's current address book interface. Do I have to re-implement everything from scratch (contacts divided by letter headers, all alphabet buttons on the right, and so on) or is there a way I can somehow use and modify the PeoplePicker view?
(I'm still pretty new to the IPhone SDK, feel free to ask any questions that will help elaborate my question.)
Well, with UITableView you can do pretty much 100% what the regular "select a contact from a list" part of the addressbook does and then build upon that.
from Oreilly's "iPhone SDK Application Development" book
here is a more detailed answer of:
Well, with UITableView you can do
pretty much 100% what the regular
"select a contact from a list" part of
the addressbook does and then build
upon that.
You basically have to implement sections and the index bar methods for a UITableView. (based on my shallow reading) the following methods need to be implemented:
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection (NSInteger)section
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (NSInteger)tableView:(UITableView *)tableView sectionForSection IndexTitle:(NSString *)title atIndex:(NSInteger) index