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.
Related
I am using a UICollectionView to show an array of images, horizontally and zoom in/out that image in the cell with the help of scroll view using constraints. But when I scroll horizontally it shows me previous cell content in the current cell. I am and not able to identify what is the problem.
CollectionView datasources
CollectionCell Class
try this when you reuse the Cell in cellForItem at
cell.imageView.Image = nil
Please share some code so that we can help you better. Meanwhile, make sure you have the following parts working correctly in your code:
Register correct UICollectionViewCell subclass with correct reuse identifier
Use the method [self.collectionView dequeueReusableCellWithReuseIdentifier:itemIdentifier forIndexPath:indexPath] and pass both the parameters correctly.
In UICollectionViewCell subclass, override prepareForReuse and reset the UI parameters there.
Override prepareForReuse in imageCell class, and set imageView.image to nil.
The contentSize of the scrollView should be as big as imageView.image.size, or just use MWPhotoBrowser
Following https://stackoverflow.com/a/7313410/1971013 I need to get the height of each of my cells in - (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath.
But when I do:
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
MyTableViewCell* cell = (MyTableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];
return cell.height;
}
this (of course) results in unwanted recursion blowing up my app.
Any ideas of how I should do this?
The best answer is, sadly, I don't know. That's up to you here. The heightForRowAtIndexPath from UITableViewDelegate is what the UITableView uses to ask you what the height should be. In this function you are determining that.
Perhaps you can save it in your own memory in cellForRowAtIndexPath after you dequeueReusableCellWithIdentifier.
But if your linked questions are any indication, you're trying to expand a selected cell, correct? You can determine if it's the selected cell via
if ([indexPath compare:[tableView indexPathForSelectedRow]] == NSOrderedSame)
return 88; // some expanded value
else
return 44; // the default value
Gutblender is right: in the usual case, you don't ask a cell its height, you tell it.
It's important to embrace the fact that cells are recycled. From a practical perspective, you can't examine cells that are off screen because they don't exist.
Cautions aside, here are the options:
Create a method that defines the height of your table view cells, and use that method to calculate the value you return from heightForRowAtIndexPath. You can then call that method from elsewhere to determine what the height of the cell will be at a given index path, whether or not it exists. This is the standard approach. It's also, 99.9% of the time, the correct one.
Iterate through the table view's subviews. A bad idea because you don't control the NSTableView class, and the view hierarchy can change. And, again: cells are recycled.
Create custom table view cell class, use something like the MVVM design pattern and let your model objects vend the table view cells. You won't have to worry about the view hierarchy, but again: cells are recycled – you will end up managing stale or incorrect state.
One method I've used on static table view's that don't have any reuse and the cells are pre-generated, is create a subclassed tableView cell with a height property, so in heightForRowAtIndexPath you can get the cell for that indexPath and return the cell's height you hard-coded in that you wanted for the cell. That way, any time you want to change the height you can change it directly on the cell itself and when you reloadData it should update the cell height.
I have a UICollectionView like following:
Is it possible to add scrollable content in the middle of rows on click of a cell like following:
If yes, then how?
You can use this sample to your own need.
Expandable UICollectionView
What you can do is create 2 custom UICollectionView layouts. One without spacing and another one with it. Then animate change of the layout using method:
setCollectionViewLayout:animated:completion:
I'm going to have to assume you're using UICollectionViewFlowLayout for this purpose.
What you can simply do is add a new Cell at the desired indexPath and in the sizeForItemAtIndexPath datasource method, return the desired size (full width, required height). The flow layout will handle the rest for you.
Inside that cell, you can use a UIScrollView to get the Scrollable Content.
Update
Your cellForItemAtIndexPath:(NSIndexPath *)indexPath will look something like this
if(indexPath.item == myItemIndex && indexPath.section == myItemSection)
{
return CGSizeMake(768,200);
}
else
{
return CGSizeMake(128,128);
}
The values above are just examples. Modify them to suit your needs.
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...
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.