UITableViewCell like mail on iphone - objective-c

How can I adjust a UITableViewCell so that it would show two fields after swiping it left - identical to how the mail client does it?
Right now I only see the "Delete" button.
I would like to have the "More" field included there, too...
Also, for the first if clause Cell I do not get a "Insert" field.
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == self.reports.count){
return UITableViewCellEditingStyleInsert;
} else {
return UITableViewCellEditingStyleDelete;
}
}
Is there a way to combine the fields with the | operator or something?
Thanks, EL-

You can use undocumented delegate methods for UITableView in iOS7
- (NSString *)tableView:(UITableView *)tableView titleForSwipeAccessoryButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return #"More";
}
- (void)tableView:(UITableView *)tableView swipeAccessoryButtonPushedForRowAtIndexPath:(NSIndexPath *)indexPath
{
[self setEditing:NO animated:YES];
}
It seems that they are not private and can be submitted to appStore.

Related

Static Table View Cell Labels are getting Squished into Header

EDIT
My constraints on custom cells are all weird. Please disregard. Just using standard Left Detail ones now.
I don't understand why in iOS8 now my static table view cell contents are collapsing into the header of each section.
There's really almost nothing in my SettingsTVC.m. This is a just a test with all static data in the storyboard:
- (void)viewDidLoad {
[super viewDidLoad];
}
Have you implemented TableView delegate methods properly i.e
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == CUSTOM_SECTION)
{
return CUSTOM_VALUE;
}
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return height;
}

I can't edit the UITableView even if it is configured to be edited

I have a UITableView in the iPad xib file.
The delegate method:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
is correctly invoked.
But stil when I touch a row, or I swipe on it to delete it nothing happens.
In the xib file "User Interaction Enabled" for the table is on.
Thanks
UPDATE:
I've added this to the delegate, but still nothing:
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
Have you implemented these methods :
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
}
This method tells if the table can be edited.
To go into edit mode, call [setEditing:YES animated:animated].
If you have setup a editButtonItem, it will do it for you when pressed.

Dynamic Grouped Table Cells

In my storyboard, I have a UITableView and it has the following Properties
Style: Grouped
Content: Dynamic Prototypes
My question was how to make the different groups. When I run the app right now, there is no white backing (Only the default lined backing) with the text placed on top. Also, if I then created these dynamic groups, how would I set their header and footer?
Thanks
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 2;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
// implement your code
}
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
//implement your code
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
/// Write basic code//
switch (indexPath.section) {
case 0:
//It belongs to first group and implement your code.
break;
case 1:
//It belongs to second group and implement your code.
break;
}
I think it will be helpful to you

UITableView swipe return animation

I have a table, and I noticed that when I do the "swipe to delete", the red button is animated only the first time, the return (if I do another swipe) disappears without animation. These are the methods I use for this step:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
...
}
- (void)tableView:(UITableView *)tableView
didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView reloadData];
}
I forgot something to animate the return?
Thanks a lot!
Yeah, leave out the [tableView reloadData];. You only need to reload the table in -tableView:commitEditingStyle:etc:, and arguably not even then—it’s better to use the UITableView method -deleteRowsAtIndexPaths:withRowAnimation:. Reloading it is unnecessary and is why your delete button is disappearing instead of animating out.

How to manage creating a UITableViewCells?

Would you guyz be so kind to help me with such question:
I have to fill the tableView with cells and I also have an array with objects to fill cells with.
The question is - how to skip creating a cell if the object doesn't meet some conditions? I mean how to write something like:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(objectIsOk) {
//create cell
}
else {
//do nothing
}
return cell;
NOTE: I don't have an access to that array of objects it gives me an object per indexPath.row dynamically
I'm unsure as to what you mean by "skip creating a cell". Your table view data source is required to return a cell for each cellForRowAtIndexPath: call, which will get called for each row in each section that you have said the table will contain.
If you want to return a blank cell then why not just do something like this:
- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
if (objectIsOk) {
// Create normal cell
} else {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"BlankCell"];
}
return cell;
}
You could also return height of zero in the heightForRowAtIndexPath: delegate method to make it appear that it's not there, like so:
- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (objectIsOk) {
return 44.0f;
} else {
return 0.0f;
}
}