I'm using the delegate method tableview: willDisplayCell: forRowAtIndexPath to make visual changes to my UITableViewCell's with. The problem is that this only seems to work after I scroll through the table. The cells that are shown before I scroll don't have a change until I scroll. My delegate method is as follows:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.frame = CGRectMake(0,0,300.0f,100.0f);
}
Any ideas as to how I get the initial cells to look the same as they do once I scroll?
I don't think you can change the frame of a cell during
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
try this instead.
- (void)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
Related
I have just added a UITableView in to my storyboard and the suggested constraints to it like that.. Now i have written very simple code with some delegate and datasource methods implemented like this. . Now when i tap the first row it detects nothing and check the console in the below image, when i press the second row it tells me that the indexPath.row is 0.. can some body point out that what i am doing wrong here.
You are calling -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath which is called when you deselect row , instead call
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
It's because you are using didDeSelectRowAtIndexPath: instead of didSelectRowAtIndexPath: method.
You have to call "didSelectRowAtIndexPath" Delegate method.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
This method only return which row we have selected.
I have these 3 delegate methods implemented for my swipe to delete handling, but nothing is happening and none of these methods get called.
//returns UITableViewCellEditingStyleDelete
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
//removes deleted object from my tabledata array
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
//checks if data actually can be deleted (all set to yes currently)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
what exactly am i missing? im swiping all day long on my table cells but nothing happens.
Make sure you have the DataSource & Delegate connected up to your view controller
and also make sure you refresh the table when done using [self.tableView reloadData];
As part of a table, is it possible for TableViewCell to have different heights?
If, so, how can this be done?
Using the UITableViewDelegate method :
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
Yes you will have to override the following function for your tableview datasource delegates::
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
I'm having the following problem.
I have an app using a UITableView with a custom UITableViewCell. Because of the specs of the app, I need it to be in edit mode always, so on the viewDidLoad I wrote this:
- (void)viewDidLoad
{
MainTableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"compose_background.png"]];
[MainTableView setAllowsSelectionDuringEditing: TRUE];
[MainTableView setEditing: TRUE];
[super viewDidLoad];
}
Also, I've implemented the following methods:
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
- (BOOL) tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
And several more, but the problem persists and when I swipe a cell the delete button doesn't shows up. Any pointers would be highly appretiated.
- (UITableViewCellEditingStyle) tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath must return UITableViewCellEditingStyleDelete for each row you want to delete. Swipe-to-delete is disabled in favor of this method when in editing mode.
I don't think there is anyway for the standard swipe to delete to work while the table view is in editing mode, you'd have to respond to gestures and add your own delete button.
I'm trying to delete a row using Xcode 4.2 and a storyboard. The Table is nested in a UINavigationController nested in a UITabBarController.
My UITableViewDelegate class implements the following code:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCellEditingStyle result = UITableViewCellEditingStyleNone;
if ([tableView isEqual:self.tableView]==YES) {
result = UITableViewCellEditingStyleDelete;
NSLog(#"hi");
}
return result;
}
and when I swipe a row, I see the "hi" message in the log, but the row never receives a "Delete" button. Looking at sources like http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1, my
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"hi2");
}
method is never called.
Thanks!
Check if method - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath returns YES for appropriate index paths.