Adding a custom cell at the end of tableview - ios

I have a situation where I need to display more than one sections in a grouped table. Each section has three content rows and I need a "View More" row. The content row will open a detail view, where as "view more" will open a tableview with status messages. Need some help with
The prototype cell is set to have the image and the labels. So I am not sure how to add the "View More" Row in the end.
Am I right in using dynamic prototypes ( I have it working pretty much) or is static cells the right choice?

The prototype cell is set to have the image and the labels. So I am not sure how to add the "View More" Row in the end.
You are not limited to a single prototype cell per table. Add a custom cell for the "View More" cell, then add some code to your tableView:cellForRowAtIndexPath: method to pick the "main" prototype for the top cells, and the "view more" prototype for the last cell.
-(UITableViewCell *)tableView: (UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath {
UITableViewCell *cell;
if (indexPath.row != [self numberOfRowsInSection:indexPath.section]-1) {
cell = [tableView dequeueReusableCellWithIdentifier:#"mainPrototype"];
...
} else {
cell = [tableView dequeueReusableCellWithIdentifier:#"viewMorePrototype"];
...
}
return cell;
}
Am I right in using dynamic prototypes ( I have it working pretty much) or is static cells the right choice?
Yes, this is the right choice.

Create an array to contain all the status messages. Group them according to the section when you initialise the screen. You could give the same index to the groups as the section as well. In the didSelectRowAtIndexPath method, when a particular section is clicked, pass the particular section of the status messages to the next view controller.
Hope you get my idea and this helps you..
Adding the custom cell to the end of each section can be done as #dasklinkenlight said...

Related

How to customize my UITableView cell as below

Am using custom tableview cell in my code. Please can anybody help me how to write the code for common friends cell. How can i get the names AMANDA,VIKA LEVINA,NATASHA,KATE,JESICA names in rectangular box.
For common friends and Facebook interest cells you can use UICollectionView and adjust cell width depends upon text otherwise you can use one of below listed controls.
https://www.cocoacontrols.com/controls/jctaglistview
https://www.cocoacontrols.com/controls/taglistview
https://www.cocoacontrols.com/controls/antagsview
you have to design two custom cells in your IB first for image view cell and other for list given below in your cell. create two custom cell in IB and design them according to your need and after that in your cell for row at index path method differentiate between these cell like:
uitablviewCell *cell;
if(indexPath.row == 0)
{
cell = [tableview dequereusablecellWithIdentifier:Firstcell];
}
else
{
cell = [tableview dequereusablecellWithIdentifier:secondCell];
}
For common friends and Facebook interest cells, You can use ANTagsView.
Using this, You can get tag view which you are showing in image.
So this view, you can add into your cell. For tags view, you have to pass array according to your view.
And set height of cell dynamically using heightForRowAtIndexPath method.
After that, you can get your view.

How can I get index path of cell on switch change event in section based table view

I have custom cell having switch in few cells at right side. what I want is to store value of specific cell on switch change event. Table view has number sections so I can't set tag for switch because I need section as well as row to obtain index path.
Any suggestion any alternative but I have to use UISwitch in section based table view.
Thanks
In your custom cell add properties which help you identify the information the cell represents. Index path, indexes for your data model etc...
Then add a block property to the cell which you can call to tell a UITableView or any other piece of code when a cell switch changes. e.g.
#property (nonatomic,copy) void (^onSwitchChange)(UITableViewCell *cell);
Inside your custom cell code, add an action handler for the UISwitch. When it fires, call self.onSwitchChange(self) which will notify the code which registered an onSwitchChange block that a switch has changed and on which cell.
In your table view when you create the cell, set the onSwitchChange block as follows:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath
{
<snip>
YourUITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:yourCellIdentifier forIndexPath:indexPath];
cell.onSwitchChange=^(UITableViewCell *cellAffected){
// Add code to deal with the swicth switch using properties of cellAffected
... Your handler code here ...
}];
<snip>
}
This lets you handle all the changes in the table view controller. Hope this helps.
The answer from #Jageen works. I had to find out which superview the cell is, mine was one more level higher.
UITableViewCell *cell = (UITableViewCell*)[sender superview].superview.superview;
NSIndexPath *indexPath = [self.myTableView indexPathForCell:cell];
NSLog(#"Section %ld Row : %ld",(long)indexPath.section,(long)indexPath.row); // print row section and index
You can still create tags even if you have sections if you have some idea of about max rows in a largest section. For example if you think there will be 1000 rows in a section then you can create tag using following formula.
tag = section * 1000 + row;
later in your IBAction of switch you can find out the indexpath (section and row) using following:
section = tag/1000;
row = tag%1000;
If you have no idea of how many rows your section will have you can find out the cell using sender.superview.superview (be careful if have added any other views in hierarchy).
Rory McKinnel's answer is still the cleanest solution for your problem.

How to select multiple cells in a table view

I have a table view with multiple cells. When I click on one of the cell it navigates to the next view controller, but my problem is that I cannot select multiple cells.
Could any one please help me on this issue, I want to select two or more cells with two finger tap.
set by code if you set by programming
table.allowsMultipleSelection = YES;
and if you set in xib tick on allowsMultipleSelection
Just add button like checkbox and multiple choose like checkbox.
If you are implementing the tableview programatically then the better way is to create a custom cell which will have button (and obviously other UI components that you need to show in the table view cell) which will work as a checkbox and assign button.tag as indexPath.row which will help you to select multiple rows.
Take a look here --
Below code will go into cellForRowAtIndexPath
YourCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:#"Cell" forIndexPath:indexPath];
cell.button.tag = indexPath.row;
[cell.button addTarget:self action:#selector(multipleCheckAction:) forControlEvents:UIControlEventTouchUpInside];
return cell;
-(void)multipleCheckAction:(UIButton *)sender { //sender.tag will be equal to indexPath.row }
Happy Coding
Since cells are being reused, you need to set the accessory mark to on or off for every cell in the table in the cellForRowAtIndexPath table datasource method.
So the cell.accessoryType cell property should be specified in the cellForRowAtIndexPath and not the didSelectRowAtIndexPath delegate method.
In the didSelectRow, just keep track of the selected rows in an array, and set the cells accessory mark to none or checkmark in the cellForRowAtIndexPath depending on the array value.

For iOS UITableView, can i load a specific row WITH CUSTOMIZE CELL XIB?

It's My first time to post a question, thank you for you all in advanced.
Now, i want to implement a default style grouped UITableView contains multiple group of data. for each row, there will be a detail Disclosure button as accessoryType icon. when people click on the disclosure button, i want the Cell expand with detail info for the selected row.
i was trying to fulfill this task by add a customized cell to selected row, however, it was very complex. So currently, i am trying to finish this task by reload a specific row with Customized cell xib. i knew there is a delegate method for reloadRowsAtIndexPaths. but can i use this to reload a specific cell? Thanks
please suggest!
Great Thanks
Have you tried something like this:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == mySpecialSelectedCell)
{
//Load all your custom stuff here
}
else
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
}
if (cell == nil)
{
}
return cell;
}
You would have to get the cell's indexPath when you click the expand button.
Or you could look at this answer. And then, like the code above, just load that one cell that you have specified with that NIB and load the rest the way you would normally.
You can implement the tableview delegate methods to set the height for the cell which needs to expand. Add some condition check in heightForRow method and when user taps on button, change the condition to increase the height. When table is reloading it will call this method and will reload cell with bigger height.

Table view cell expandable iOS

I want a table view with only cels, and when you click on a cell it should expand and show more info of the clicked cell.
I've seen quite some topics on this, but the most of them are linking to Table View Animations and Gestures on the apple developer page. Which does it in a different way. They use header sections, but I want to use the cell which is expandable for layout reasons.
I already tried several things mainly with
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (isSearching && indexPath.row == selectedIndex) {
return 110;
}
else {
return rowHeight;
}
When I Click on the cell, the cell is expanded but the info in that cell stays the same. Also the heigth of the cell when expanded should be related to the amount of text in the details.
Thnx!
You can achieve this through the use of custom cells. Create two custom cells, one for the normal row and other for the expanded row. When the user touches a particular cell, you can record it's indexPath and reload the tableView. While reloading you can change the height of this selected row using the code that you've just posted(increasing the height of only the selected cell). This would give an effect of expanding cell.

Resources