Swift Preserve UIswitch State on UIlongpress

Swift How to add the shouldReceiveTouch on Switch?

Please try to use this line

let newSwitch: UISwitch!

instead of

var newSwitch: UISwitch!

UISwitch not reaction

You have created ViewController, but not presented it. So loadView was never called and yours .switch is nil.
try this:

ViewController *vc = [[[ViewController alloc] init] autorelease];
[self presentViewController:vc
animated:YES
completion:^(){
vc.switch.on = variable;
}];

iOS - indexPathForRowAtPoint don't return correct indexPath with different cell height

One way to do it would be to add a UILongPressGestureRecognizer to each UITableViewCell (that all use the same selector), then when the selector is called you can get the cell via sender.view. Perhaps not the most memory efficient, but if the single gesture recognizer won't return the right row in certain situations, this way should work.

Something like this:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

...

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(handleLongPress:)];
[longPress setMinimumPressDuration:2.0];
[cell addGestureRecognizer:longPress];
[longPress release];

return cell;
}

then

- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {  
UITableViewCell *selectedCell = sender.view;
}


Related Topics



Leave a reply



Submit