I was wondering if there is a way to make a UITableView editable in a way where the user is able to rearrange (move) individual TableViewCells, BUT without the "Remove-Cell"-Feature to appear.
thank you for your help
sam
Have you tried implementing the editingStyleForRowAtIndexPath method and returning UITableViewCellEditingStyleNone?
You change the if condition based on your requirement
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
// in below if your write your condition on which delete is enable or disable
if ([[friednListArr objectAtIndex:indexPath.row][#"id"] isEqualToString:user.userId]) {
return UITableViewCellEditingStyleNone;
}
else{
return UITableViewCellEditingStyleDelete;
}
}
Related
I creating the one UITable view with the 2 sections in with when i load the data into the uitablew it's working fine,
But my problem is how to resolve one sorting button is disable in section 0 and row 0
which more discribe into the following image.
please help to solve my problem
in advance thanking to your valuable time spend on my problem.
It's quite easy.
Listen on the UITableViewDataSource call tableView:canMoveRowAtIndexPath:
Like this:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.section == 0) {
return NO;
}
return YES;
}
If you don't not where to place the method, place it next to tableView:cellForRowAtIndexPath:
Set showsReorderControl to NO property of cell
cell.showsReorderControl = NO;
In addition, if the data source implements tableView:canMoveRowAtIndexPath: to return NO, the reordering control does not appear in that designated row. You need to check indexPath and return NO for it.
Two UITableViewCell related questions:
In my custom UITableViewCell I loop through an array (of which I do not know how many objects it holds) and add a UILabel displaying some text for each object in that array.
This means I have to adjust the height of the cell so that these labels fit in. How can I do this?
When going into edit mode, I have the cells indent, however I do not want this. I have tried the following:
cell.shouldIndentWhileEditing = NO;
and
-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
Both sadly failed, I have I no idea why. How could I possible remedy this?
Any help is much appreciated with either of these issues, thanks.
You can specify the height for every row with the delegate method [UITableViewDelegate tableView:heightForRowAtIndexPath:].
Just change what the method returns and the reload your table.
This method actually has nothing to do with the indendation of cell content:
Asks the delegate whether the background of the specified row should be indented while the table view is in editing mode.
You can try to set indentationWidth but I never managed to make it work.
Fortunately, it's easy to change everything you want in [UITableView layoutSubviews] method.
Example:
- (void)layoutSubviews {
[super layoutSubviews];
self.contentView.frame = self.bounds;
}
You may also need to set
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return UITableViewCellEditingStyleNone;
}
For the dynamic height part there are plenty of other answers and a quick google found a tutorial here
In a tableview, I need to prevent a cell from being created by a given condition.
For example, I have a tableview that shows a couple of results but I want the app to filter them. Is a way to do this?
Best Regards.
Preventing a cell from being created doesn't sound good. The simplest way to do that is to implement correctly the ...numberOfRowsInSection: method given the condition :
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(condition) {
return theNumberOfRowsGivenTheCondition;
}
else {
return someOtherRowsCount;
}
}
Hello
I am developing an app which is using a tableview with two sections(instead of radio buttons).
So I want these section to act like radio buttons. To accomplish this, I have to implement an "if" in the
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
I want to use something like: if (section == "A").
How to do that?
Also is this the right way to make the sections of a table acting like a different tables?
Hmm... that sounds like an odd set up, but irrespective, you simply use the provided indexPath to obtain the section/row.
i.e.: indexPath.section will point to the selected section and indexPath.row will point to the row.
For more information, the Table View Programming Guide for iOS is a good start as it covers all of the above in quite a bit of detail.
UPDATE
In terms of highlighting multiple cells, I'd have thought that you'd want to create your own concept of highlighting, which you'd toggle on and off when the user selects the cell.
That said, you could also mark selected cells via the UITableViewCellAccessoryCheckmark as per the existing Is it possible to configure a UITableView to allow multiple-selection? question/answer.
I don't know what you mean by "section to act like radio buttons" but to distinguish between sections in tableView:didSelectRowAtIndexPath: use indexPath.section:
if (indexPath.section == 0) {
// first section
} else if (indexPath.section == 1) {
// second section
}
you must need to use indexPath.section: to distinguish between your table sections
So your code should be like below .
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
{
if (indexPath.section == 0)
{
//first section
}
else if (indexPath.section == 1)
{
//second section
}
}
I have 2 sections in my UITableView. I want the 2nd section to be movable but the 1st section of cells not.
Specifying canEditRowAtIndexPath and canMoveRowAtIndexPath doesn't help - the first section cells although not showing drag controls, they still change places if a cell from the 2nd section is dragged over.
Is there a workaround for this?
Try implementing the targetIndexPathForMoveFromRowAtIndexPath method and forcing the row from the second section back to its original place if user tries to move it to the first section:
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
{
if (proposedDestinationIndexPath.section == 0)
{
return sourceIndexPath;
}
else
{
return proposedDestinationIndexPath;
}
}