I want to create a custom cell for uitableview with an image at left side such that the following things happen
1)When the cell is selected , its height is increased , background color is changed and it gets a green color circular button at the position of accessory view
MY APPROACH :- I made a custom uiview such that it contains an imageview at the position of accessory view ,
and then i did
[[table cellForRowAtIndexPath:indexPath].contentView addSubview:customCellBackgroundView];
but this didnt work , because it hide the cell's text
2)the selected should remain of the same height , such that more than one cell can be selected and the selected cells have larger heights than the unselected ones
You can keep a property for each cell that says if it is selected or not. When drawing each cell you check to see if that cell is supose to be selected or not and use 1 of 2 different cell layouts you previously created (one collapsed and the other opened).
So when you click some cell, you change the selected state of that cell and call for a reload of the tableview so that the same cell is now drawn as opened/closed.
Related
In Swift,I have a tableview and in that many tableview cells. In the tableview cell I have a UIImageView in which there is an Image . So now I want to dynamically change the colour of the image everytime the tableview loads,so that the image is visible to the user and the transparent colours on the images are maintained everytime the reload of the table happens.
Suppose there is - 1 TableView - multiple cells
- cell1(UIImageView - transparent redcolor) - UIImageView(tranparent bluecolor) - cell3(transparent yellowcolor) so on........how to do it dynamically?
You have two options:
configure the bleeding color in cellForRowAtIndexPath. Specifically you need to set the .backgroundColor property on the UIImageView that holds the image.
have a configureWithColor method in the custom cell (if you have a custom cell) and do the color configuration there.
see below figure, it has- TableView & tablecell have same background image i.e.tableview & tablecell must not look different. in tableCell there must be one button .
To achieve this you'll have to create a customized UITableViewCell.
You'll required 4 background image for your cell.
a. Image Facing right. b. Rollover image facing right. c.
Image Facing left. d. Rollover image facing left.
You'll have to set alternate image to your cell. And when you click on the cell you'll need to change the background image of that particular cell to Rollover image.
Also you'll have to manage the frames of your rest of the control accordingly.
This is nothing but the image. You have to set an image in every tableviewcell by passing the condition
if(indexpath.row/2 == 0)
<set_image1>
else
<set_image2>
then adjust other parameters according to your desired frame position.
Note: You need to use dynamic tableviewcell height &
You need for images for this.Two when cell is not selected & rest two when cell got selected
Enjoy Programming!
I did this following way:
I created two prototype cells having different Cell identifier
e.g. left cell identifier= Cell1 & right cell identifier=Cell2.
simply put one round-rect button, make it as custom because it shows only in image shape
made table cell background color as clearColor, it requires because for the feel of table cell & tableview must look same.
also set tableView background color as clearColor & add images to both button.
if ((indexPath.row)%2!=0)
{
CellIdentifier=#"Cell1";
}
else
{
CellIdentifier=#"Cell2";
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIButton *topicButton=(UIButton *)[cell viewWithTag:1];
NSString *topicNameLabel=[_topics objectAtIndex:indexPath.row];
I am creating a grouped table with two sections.In the first section i have 5 cells and in the second section i have two buttons in the lass cell of it.
I have created labels and buttons on each of the cells in the first section and the labels are populated dynamically by the values selected in the previous screen.
Everything works fine as expected,except the borders of the table view gets ruined,it looks like half drawn and incomplete.When i make the table view to scroll up and when its back in the original position,the top borders are spoiled and when i scroll to the bottom the lower borders of the group gets affected making them incomplete.
I am setting the label's and button's attributes in each of cell after initializing them in the viewDidLoad method.
Please suggest me an idea to solve this issue.
Thank you one and all
I am setting the label's and button's attributes in each of cell after
initializing them in the viewDidLoad method.
This is incorrect. You should save the texts for the labels & buttons in a model class & set them in the cellForRowAtIndexPath: method. As, you are not doing this in the aforementioned method, your cell is redrawn when you scroll and the texts are nullified.
I have a custom table cell having a uiview and 3 labels. on the uiview there is an imageview. i am detecting touch and on the uiview/imageview. on touchesended method i am changing the image of the imageview on this uiview.now after running the program 7 rows are visible on the table. if i touch on the imageview of 1st row, the image gets changed. Now if i scroll the table, the image of the imageview on row 9th also gets changed itself. Can any one pls help me out whats getting wrong?
if you use reusable cells, after scrolling the table view will consume the same cells you've set up in the cellForRowAtIndexPath method. So it might be that the cell for row 1 and for row 9 use the same cell object. That explains, that when you change something in row 1 cell, the row 9 cell will be changed in the same way. Just be sure, that when you setup your reusable cells to nil the image of your uiimageview, or feed it with a proper image.
I have a UITableView with custom cells. The cells containing one UITextView each and the cell is resizing during user type text in the TextView. My problem is when user is on first row in a TextView autocorrection bubbles wont be visible in the current cell. Is there any workaround or can someone point me to another direction?
alt text http://img340.imageshack.us/img340/5414/skrmavbild20100519kl092.png
If the cell is resizing as the user types, you could set the minimum height of the edited cell to have enough height for the bubbles. Always measure the active cell as if there were at least two lines.
Each UIView has a clipsToBounds property that controls wether contents can be drawn outside the bounds. You might be able to set this to NO for all views in the hierarchy between the bubble and cell. This could have other side effects though.
Also, make sure the active cell has a higher Z order than neighboring cells. It could simply be that the next cell down is drawing over the bubble, as opposed to the active cell cropping the bubble.
I propose you a "workaround"
Your user try to edit a row in your table view
-> You present a modal view with a UITextView with dismiss and ok button.