Radio button functionality on a UIView in custom table cell - iphone

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.

Related

Giving images to different cells of tableview

I have a tableview in a collectionView having 5 sections and each section has 10 rows. Each cell has to be given different images.I am new to ios and have very less idea on this.
Design A custom tableviewcell with a Image View, in Tableview's datasource Method -cellForRowAtIndexpath : assign image on imageView as you wish.

UITableView Grouped table border issue

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.

pop up detail view out of tableviewcell

I am working on a app where I want to expand a tableviewcell to cover almost all the screen with animation when it is selected by user. I am looking to create a uiview on the tableviewcell and expend it to cover major portion of the screen when user selects the row.
The main problem I am having is to get the frame from where my pop up view will start expending. How will I get the frame of the row which is touched?
Thanks
Pankaj
Is it crucial that the cell should not reposition?
If not ( i am guessing not, as you are anyway planning to cover whole screen):
When the cell is selected, scroll the cell to top (using scrollToRowAtIndexPath) and either insert your custom view to cell's contentView or modify its parameters if its already there with different opacity/size etc
Use UITableView function to get the rect for the row by passing the its NSIndexPath.
- (CGRect)rectForRowAtIndexPath:(NSIndexPath *)indexPath

Can a UITableView (not UITableViewCell) have variable size?

I have a UIView (created in IB) with a grouped UITableView as a subview. Below this table view is a UIButton. The XIB containing the view will be loaded by a few different viewcontrollers, and so the contents of the table view can vary between one and four cells.
Here's what I want to achieve: when the view loads, the height of the tableview (tableView.frame.size.height) should be adjusted depending on the number of cells, and the button should be placed just beneath the table view.
Can this be done? Could it somehow be done if the view is created programmatically?
Thanks in advance
Edit: Pxl's suggestion was just what I was looking for. A while later, the need arose to have more than just a button below the table view - this was accomplished by creating a separate view containing everything I needed, and implementing the tableView:viewForFooterInSection: and tableView:heightForFooterInSection: functions.
A note for those of you trying to do the same thing: the tableview has to be programmatically created if you want different heights for the footers, or footers for only some of the sections. This is because the footer height set in IB will override the one returned from the tableView:heightForFooterInSection: function.
if there are only a handful of rows, may i suggest that you create a special UITableViewCell that contains just a button?
then make that button cell the bottom row of the last group all the time. make the group so that it will be unlabeled and appear as if the button is sitting at the bottom of your tableview. this way you won't have to muck around with recalculating the tableview's frame and redrawing it.
if the tableview will scroll due to there being many rows, then you'd be calculating the height of the tableview up to a set max (at which point the tableview will need to scroll to show more rows).
once you've determined the height of the tableview you'll need to display your rows, make a frame of the appropriate size, set the tableview's frame to it, position the button just under the tableview, and then redraw the view.
the layout and positioning in this case will need to be done programmatically.
UITableview is a subclass of UIView, so you can change its frame to suit your needs just like a UIView, and UITableView will manage drawing itself to whatever frame you give it.
Just use the methods UITableViewDataSource and UITableViewDelegate provides you.
height = [self tableView:numberOfRowsInSection]*[self tableView:heightForRowAtIndexPath:] + A_CONSTANT_FOR_HEADER_AND_FOOTER_HEIGHT
I agree with pxl that adding a cell with the button in it may be the easiest way to accomplish what you want.
Whether or not you do that, the table view's sizeToFit method should resize the view to (just) fit its contents. If that doesn't work, you can use numberOfSections and rectForSection: to build a loop that determines the height of the table's contents, and reset its frame manually. (And then position the button underneath.)

Scroll complete tableView while updating tableviewcell

I have just three custom tableViewCell rows in my tableView. First and second are with label while third is with TextView, i want to autoscroll complete tableView as i type in TextView (3rd row) cell and there is no visible typing space. Can anyone help me providing some guideline, how to achieve this?
When the text view delegate receives the didBeginEditing call, change the frame of the table view so that it's position is moved upwards. Wrap that up in a UIViewAnimations block and it'll scroll nicely.