How to distinguish two UITableView having a same custom cell - ios

Hi I have two UITableView in a UIView class and are loaded with same custom UITableViewCell. Custom tableview cell contains a UITextField. That means the two UITableView contains a UITextfield of same custom cell. When I select any of that textfield, how do I know which tableView's textfield is selected? Please help me..

UITextField *txt = ----;
txt.superView.superview will give you the required UITableView instance.
To be more clear :
UITableViewCell *cell = txt.superView; // In your case custom cell
UITableView *yourTable = cell.superView;

Related

Display label in UITableview cell When its visible in Ios

I am new to iOS. I need to show the Label in timeDelay in UITableViewCell only when its visible?
Create a custom UITableView cell. In your cellForRowIndexPath, call the function performSelectorWithDelay which will show your UILabel.
When the cellForRowIndexPath is called, it's pretty certain that the cell will now be shown.

Detecting taps on Custom Cells of UITableView

So i have a custom UITableViewCell which contains three UILabel. The UITableViewCell is such that the UILabel completely cover the cell.
Now i want to detect whenever user taps on the cell. Problem is as the UILabel cover the cell I cannot use UITableView delegate method for detecting touch on the cell.
I thoughout about using gesture recoginzers on the UILabel but then i don't get the index of the touched cell. I also thought about placing a transparent button on top of the cells but here there is also the same problem that i can't get the index of the touched cell.
Can anybody guide me with an approach on how can i accomplish detecting taps with tableView didSelectRowAtIndexPath when UILabel are covering the cell.
Try to set userInteractionEnabled to false in all labels in cell. This will pass touch to the cell and then you can use UITableView delegates. Be sure that cell stays userInteractionEnabled = YES
To get the touch event besides didSelect method try this. In your custom cell class add a block like,
typedef void(^TappedCell)(CustomCell *cell);
and add a property for it,
#property (nonatomic, strong) TappedCell tappedCell;
and on transparent button action
- (IBAction)buttonTapped {
if (self.tappedCell) {
self.tappedCell(self);
}
}
And in cellForRow method
__weak type(self)weakSelf = self;
cell.tappedCell = ^ (CustomCell *tappedCell) {
//Ur actions goes here
//for getting index
NSIndexPath *indexPath = [weakSelf.tableView indexPathForCell:tappedCell];
[weakSelf someActionWithIndexPath:indexPath];
};
It doesnt matter whether UILabel hide your cell or UIImageView hide it. It will automatically detects tableView didSelectRowAtIndexPath. Check it first you wont face any problems. Did you try to implement tableview in detail first

UITableViewCell make only part of cell selectable

I have a custom TableViewCell and I would like that user can only tap/select the part of the cell in tableview.
I guess that this would be possible if I make the my CustomCell non selectable and then add UIButton inside my CustomCell on which the user can tap.
But are there any other ways of doing it?

Making custom, dynamic tableview cells

I am struggling to figure out how to get complete control over my tableview cells. I want them to look something like this:
Right now I need to know how to properly manage my cells. Should I make a table view cells subclass? Should I be doing this all within the storyboard of the tableview? That's what I'm doing now. Also, how do I implement dynamic cell heights based on the amount of lines of text?
Thanks
You should subclass the UITableViewCell class and create your own custom cell using XIB. This will give you a lot of leg room for dynamism.
Refer to this tutorial for how to do so:
http://www.appcoda.com/customize-table-view-cells-for-uitableview/
U can create a custom view and use the followingin the cellForRowAtIndex
static NSString * cellIdentifier=#"MyTableView";
UITableViewCell * cell;
if(cell== nil)
{
cell = [myTableView dequeueReusableCellWithIdentifier:cellIdentifier];
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
contentCell.tag =100;
contentCell=[[ContentOfCell alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
[cell.contentView addSubview:contentCell];
}
else{
// Reusable part. Reuse the UI controls here from existing cell
contentCell = (ContentOfCell *)[cell.contentView viewWithTag:100];
}
//Assign all the data here
contentCell.nameField.text=[arr objectAtIndex:indexPath.section];
//same way for other fields
}
Where contentCell is a custom view
I will try to answer your question in three parts :
For Dynamic cell height which is based on text content : you have a table view delegate called heightForRowAtIndexPath, you should calculate the height of the text based on its font and font size characteristics, and of course by providing the available width, for this you can use method "sizeWithFont" of NSString.
For more control on the cell appearance : you should make a table view cell subclass and use it in the cellForRowAtIndexPath.
Should you be doing this using storyboard : It is not necessary to do it using storyboard.

Modify outlet inside UITableView custom cell

I have a custom UITableViewCell that has 2 UITextFields and a UIButton. The text fields are set in the cell:ForRow:AtIndexPath: method. What I need is to change the opacity of this UIButton dynamically, without having to reload the entire tableview. I was thinking of something like cellForRowAtIndexPath:, but how to access the outlet in this cell?
Thanks
When you create the cell in cellForRowAtIndexPath: just maintain a pointer to it in code. If that button is on every cell then you can just create an array of buttons so that you can easily access the button for the cell you want.
UIButton *cellButton = [[UIButton alloc] init];
[allCellButtons addObject:cellButton];

Resources