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.
Related
Under iOS 5, it seemed that a UITableViewCell subclass's willMoveToSuperview: method was called every time the cell was used or reused, but under iOS 6, it seems that it's only called when the cell is initially created and used, not when a cell gets reused. Can anyone verify this difference? Is this a bug?
What method should I be using to do cell setup inside the UITableViewCell subclass that will get called when the cell is reused in both iOS 5 and iOS 6?
I've been having the same issue with UICollectionView. It seems you have to implement the method prepareForReuse in the view you are using for display (ex. of type UITableViewCell or a UICollectionViewCell). However, this also gets called even if it is the first time creating a cell (not just when it is being reused) if you are using the new dequeueReusableCellWithReuseIdentifier:forIndexPath: with a registered class with registerClass:forCellWithReuseIdentifier: in iOS6.
Reference: UITableViewCell Class - prepareForReuse
1. How to know if a cell is removed from tableview?
use this method to do something, e.g. cleanup, stop timers or something else...
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
2. how to know if a cell is going to be displayed
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
3. how to know if a cell is going to reuse
override this method
UITableViewCell:
- (void)prepareForReuse();
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.
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?
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.
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.