how to remove button in Uitableview when table is int edit mode - iphone

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.

Related

Collapsing and Hiding static UITableViewCells of a UITableview

I have been though a ton of examples that show how to do a collapsable tableview but I cant find something that works with static cells. I have a couple cells that I made in IB that I would like to collapse if the section header is clicked but I cant figure out or understand how to do it. If anyone can tell me or point me to an example that does that, I would be grateful.
Here is an example of just one of the cells I have that would need to collapse:
You can refer to this sample: (download the sample code)
http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html
So basically what this code does is:
You create Section in your -(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section --> Each Section has SectionHeaderView --> Which you basically will tap and expand your table view.
You will implement the two delegate methods:
-(void)sectionHeaderView:(APLSectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)sectionOpened
-(void)sectionHeaderView:(APLSectionHeaderView*)sectionHeaderView sectionClosed:(NSInteger)sectionClosed
--> This will internally call insertRowsAtIndexPaths and deleteRowsAtIndexPaths --> Which will internally call tableview:cellForRowAtIndexPath --> Now here you need to create your cell which will have address, city etc etc...
Let me know if you need more information.
I finally found a solution I was happy with thanks to this: https://github.com/xelvenone/StaticDataTableViewController
A very simple solution with the implementation:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.reloadTableViewRowAnimation = UITableViewRowAnimationMiddle;
self.deleteTableViewRowAnimation = UITableViewRowAnimationMiddle;
self.insertTableViewRowAnimation = UITableViewRowAnimationMiddle;
if (indexPath.row == 0) {
[self toggleCellVissibilityOrReload:self.cell1];
}
[self reloadDataAnimated:YES];
}

Adjust UITableViewCell Height and Indentation?

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

Properly setting up willSelectRowAtIndexPath and didSelectRowAtIndexPath to send cell selections

Feel like I'm going a bit nutty here. I have a detail view with a few stand-alone UITextFields, a few UITextFields in UITAbleViewCells, and one single UITableViewCell that will be used to hold notes, if there are any. I only want this cell selectable when I am in edit mode. When I am not in edit mode, I do not want to be able to select it. Selecting the cell (while in edit mode) will fire a method that will init a new view. I know this is very easy, but I am missing something somewhere.
Here are the current selection methods I am using:
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.editing) {
NSLog(#"Returning nil, not in edit mode");
return nil;
}
NSLog(#"Cell will be selected, not in edit mode");
if (indexPath.section == 0) {
NSLog(#"Comments cell will be selected");
return indexPath;
}
return nil;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (!self.editing) {
NSLog(#"Not in edit mode. Should not have made it this far.");
return;
}
if (indexPath.section == 0)
[self pushCommentsView];
else
return;
}
My problem is really 2 fold;
1) Even when I'm not in edit mode, and I know I am returning nil (due to the NSLog message), I can still select the row (it flashes blue). From my understanding of the willSelectRowAtIndexPath method, this shouldn't be happening. Maybe I am wrong about this?
2) When I enter edit mode, I can't select anything at all. the willSelectRowAtIndexPath method never fires, and neither does the didSelectRowAtIndexPath. The only thing I am doing in the setEditing method, is hiding the back button while editing, and assigning firstResponder to the top textField to get the keyboard to pop up. I thought maybe the first responder was getting in the way of the click (which would be dumb), but even with that commented out, I cannot perform the cell selection during editing.
Good lord I am an idiot. I never added these lines:
self.tableView.allowsSelection = NO; // Keeps cells from being selectable while not editing. No more blue flash.
self.tableView.allowsSelectionDuringEditing = YES; // Allows cells to be selectable during edit mode.
Sorry for the garbage question.
The documentation notes that tableView:willSelectRowAtIndexPath: isn't called when in editing mode. In addition, the blue flash will happen even if you cancel the selection. From the documentation:
This method is not called until users touch a row and then lift their finger; the row isn't selected until then, although it is highlighted on touch-down. You can use UITableViewCellSelectionStyleNone to disable the appearance of the cell highlight on touch-down. This method isn’t called when the editing property of the table is set to YES (that is, the table view is in editing mode).

UITableView editable (rearrangeable) without cells beeing deletable

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;
}
}

How many UITableView can place in a View?

I'm beginner in Iphone!
Can I place many UITableView (greater 1) in a View? And how to control them?
You can place as many UITableViews into a parent view, but it's probably not a good idea. Each delegate and datasource method for a tableView takes that tableView as its first argument, so it's easy to tell them apart.
Well its not a good idea to have multiple tableviews in a view but if you want it you can have them and control the by there names like
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(tableView == declaredTableView1){
return 10;
}
else if(tableView == declaredTableView2){
return 11;
}
else {
return 12;
}
}
Hope this helps.