- (void)btnClicked:(id)sender event:(id)event
{
NSSet *touches =[event allTouches];
UITouch *touch =[touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.controllerTableView];
NSIndexPath *indexPath= [self.controllerTableView indexPathForRowAtPoint:currentTouchPosition];
if (indexPath!= nil){
[self tableView: self.controllerTableView accessoryButtonTappedForRowWithIndexPath:indexPath];
NSLog(@"%d button pressed",[indexPath row]);
if ([indexPath row]== 3){
Byte byte[] = {0xaa, 0x55, 0x00, 0x7b, 0x0f, 0x01, 0x08, 0x00,
0x05, 0x13, 0x01, 0x79, 0x56, 0x34, 0x23, 0x01, 0x03, 0x53,
0x00, 0x7d };
NSData *data = [[NSData alloc] initWithBytes:byte length:20];
[_asyncSocket writeData:data withTimeout:-1 tag:0];
[data release];
[_asyncSocket readDataWithTimeout:-1 tag:0];
}
}
_accessoryBtn = (UIButton *)sender;
if (_accessoryBtn.currentBackgroundImage==self.buttonOFF) {
[_accessoryBtn setBackgroundImage:self.buttonON forState:UIControlStateNormal];
[_accessoryImages replaceObjectAtIndex:[indexPath row] withObject:[UIImage imageNamed:@"but_on"]];
}
else{
[_accessoryBtn setBackgroundImage:self.buttonOFF forState:UIControlStateNormal];
[_accessoryImages replaceObjectAtIndex:[indexPath row] withObject:[UIImage imageNamed:@"but_on_over"]];
}
}