How to detect cursor is on which Tableviewcell of tableview - uitableview

i have custom tableviewcell which has a textfield inside for user input text, now how can i find cursor is in which cell?
tableview willBeginEditingRowAtIndexPath and tableview willSelectRowAtIndexPath does not return the correct index.
in editingStyleForRowAtIndexPath i want to retun UITableViewCellEditingStyleDelete just for cell that cursor is inside. how can i do that??
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(self.uiTableView.editing)
{
return UITableViewCellEditingStyleDelete;
}
else
return UITableViewCellEditingStyleNone;
}
So thanks inadvance

in the customecell, put id that carry the index , and in creation of table when create the cell set this id with the value
http://adeem.me/blog/2009/05/30/iphone-sdk-tutorial-part-6-creating-custom-uitableviewcell-using-interface-builder-uitableview/

Related

Textfield insdie UITableViewCell

I have a textfield and two buttons inside a tableview cell and when you click on the textfield, it opens up a pickerview to make a selection. What I want is that, the user should only be able to click on the textfield and the buttons, and not on the tableviewcell. I don't want the cell to be selectable, only the textfield and buttons to be selectable, how do I do that?
I have already tried cell.selectionType and cell.userinteractionenabled but they just make the whole cell unselectable, even the textfield inside it...so that's not what I want.
screenshot of what tableviewcell looks like
Kindly help!
Thanks!
In cellForRowAtIndexPath:
if (indexPath.section == 0) {
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
}
then also implement willSelectRowAtIndexPath:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return nil;
}
return indexPath;
}

moveable but not editable rows in UITableView

If I return false in canEditRowAtIndexPath because I want to forbid delete row when swiping to left, but meantime I want to let user to change order of rows. It seems not possible. canMoveRowAtIndexPath will not get called.
Any idea how to make rows moveable but not editable?
You can do something like this:
For cell to be movable:
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
For cell to be Non Deletable:
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleNone;
}

How to avoid a tableCell scrolling when a tableCell have a view that accept user touch?

I add a UIView that can detect the user touch, drag in a table cell, but when I added it into a table cell. The tableview scrolling event get my touch instead, how can I avoid that? Thanks.
May be i am wrong but this is trick works for me.
Use tableview scrollEnabled method for that.
In cellForRowAtIndexPath at where your Detect View is there set scrollEnabled=NO , and on view detect method set scrollEnabled=YES.
i.e if user has not selected tableview cell no. 5 table is not to scroll
so in
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
..cell allocation...
if (indexPath.row==4)
{
tableView.scrollEnabled=NO;
}
return cell;
}
not enable scrolling when user tap 5 no. cell.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==4)
{
tableView.scrollEnabled=YES;
}
}

GLTapLabel Inside UITableView

I'm using GLTapLabel to display my text in my UITableView. It will have some links I can click on as GLTapLabels, but when I click those links the tableView:didSelectRowAtIndexPath: fires. So how can I detect the click action in those links?
Implement tableView:willSelectRowAtIndexPath: and return nil for any row you don't want to be selected.
Return Value
An index-path object that confirms or alters the selected row. Return an NSIndexPath object other than indexPath if you want another cell to be selected. Return nil if you don't want the row selected.
For example, to only prevent selection in the first section:
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
return nil;
}
return indexPath;
}
You can also try setting exclusiveTouch on the GLTapLabel or overriding its hitTest:withEvent: as described in the answer to Why is UIView exclusiveTouch property not blocking?.

Display UITableViewController datasource in alternate cells

I have a UITableViewController. I need to display a table cell followed by a cell that has an embedded UITextField. Basically i need to display the tableView datasource alternatively. Please help me on this.. Thanks.
EDIT #1: Imagine NSMutableArray *tableData; is the datasource for the table which has the following elements:
#"Apple"
#"Mango"
#"Watermelon"
I want the UITableView to be displayed as:
1st cell: Apple
2nd cell: text field to enter quantity
3rd cell: Mango
4th cell: text field to enter quantity
5th cell: Watermelon
6th cell: text field to enter quantity
7th cell: save button
Use dataSource method like this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return ([m_tableData count]*2)+1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == [m_tableData count]*2)
{
//cell with button
}
else
{
if(indexPath.row == 0 || indexPath.row%2 == 0)
{
//cell with label for displaying values
}
else
{
//Load a cell that has an embedded UITextField
}
}
}

Resources