what is the difference between didselectrowindexpath and willselectrowindexpath in iphone? - 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.

Related

NSUrlConnection with table view and search display controller

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?

Refresh viewForFooterInSection on didSelectRowAtIndexPath delegate

I am showing list of items on UITableViewCell in different sections. I have created UITextField in viewForFooterInSection delegate
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
Now my problem is i dont want to show viewForFooterInSection everytime. It should be nil/hidden until i click didSelectRowAtIndexPath for that particular section. And UITextField should show only for that section only.
I am confused how to reload footerView on click ?
You can reload the footer view simply by reloading the section.
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationNone];
After this call, - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section hits again, where you can keep a boolean variable and accordingly return nil or your footer view.
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if(conditionSatisfied)
return myFooterView;
return nil;
}
HTH,
Akshay
The simplest answer is simply to call [tableView reloadData]. Although this doesn't supply any sort of animation, I can't think of any nominally easy way to support animation in this case. It may be possible by inserting a row at the bottom of the section that looks like the footer, but that comes with another whole host of issues that I wouldn't want to deal with.
Edit: Just found a possibly slightly better option:
[tableView reloadSections:withRowAnimation:]. I've no idea whether this will animate the footer or not, or whether it will even make the query to your data provider, but it's worth a shot.

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.

Deleting custom cell in Table View

I am using a Table View Cell to draw custom cell in table view. Now the problem is that when I try to delete the cell in editing style UITableViewCellEditingStyleDelete only the
the little red -ve sign bitton appear and when I click it nothing happen.
Please help me and tell me how to delete custom cell in table view
Thanks
Gyani its not at all possible that when you click on (-) sign nothing happens.
May be your tables user interaction is disabled. Try enabling tableView.userInteractionEnabled=YES
And still it does not work then post some code.
hAPPY cODING...
did you implement the appropriate delegate methods? Specifically
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
Did you implement this delegate method by following form?
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// remove the cell from UITableView
[tableView deleteRowsAtIndexPaths:indexPath withRowAnimation:YES];
// remove the data from self array or something else.
...
}
}
Do you have a subview in the cell that stops the user interaction? maybe located in negative x, so it is over the delete button.

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.