您的位置:首页 > 其它

socket 发送 BYTES 数组

2013-05-13 22:42 99 查看
- (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"]];

        }

        

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: