滑块的值在套接字中传输,但滑块的视觉位置不会改变
我在 iPod 客户端和 C 服务器之间有一个连接。 我可以在移动滑块时发送滑块的数据,并正确获取服务器上的数据。唯一的问题是滑块的蓝点没有移动,它下面的标签也没有改变滑块的值。当我断开连接时,蓝点移动到应有的位置,并且标签显示其值。以下是代码:
-(void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent
{
switch (streamEvent)
{
case NSStreamEventHasSpaceAvailable:
event = @"NSStreamEventHasSpaceAvailable";
connectButton.enabled = NO;
disconnectButton.enabled = YES;
if (theStream == oStream)
{
//send data
const uint8_t *buffer = (const uint8_t *)[dataSlider UTF8String];
NSInteger err = [self writeToServer:buffer];
if ( err == -1)
NSLog(@"Error sending data.");
else
NSLog(@"Success sending data.");
}
break;
}
- (IBAction)sliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender;
progressAsInt = (int)(slider.value + 0.5f);
sliderValue = [[NSString alloc] initWithFormat:@"%d", progressAsInt];
sliderLabel.text = sliderValue;
dataSlider = sliderValue;
}
这是它应该工作的方式:服务器总是要求 printf 提供某些内容。每当服务器调用 read() 时,我都会移动滑块并发送其值。
问题:滑块在视觉上没有移动,但它的值发生了变化(我可以在服务器的 printfs 中看到它)。
有什么想法吗?
I have a connection between iPod client and C server.
I can send the data of the slider as I move the slider, and get the data on the server correctly. Only problem is the blue point of the slider doesn't move, nor does the label under it change the slider's value. When I disconnect, the blue point moves to the point it should be and the label shows its value. Here are the codes:
-(void)stream:(NSStream *)theStream handleEvent:(NSStreamEvent)streamEvent
{
switch (streamEvent)
{
case NSStreamEventHasSpaceAvailable:
event = @"NSStreamEventHasSpaceAvailable";
connectButton.enabled = NO;
disconnectButton.enabled = YES;
if (theStream == oStream)
{
//send data
const uint8_t *buffer = (const uint8_t *)[dataSlider UTF8String];
NSInteger err = [self writeToServer:buffer];
if ( err == -1)
NSLog(@"Error sending data.");
else
NSLog(@"Success sending data.");
}
break;
}
- (IBAction)sliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender;
progressAsInt = (int)(slider.value + 0.5f);
sliderValue = [[NSString alloc] initWithFormat:@"%d", progressAsInt];
sliderLabel.text = sliderValue;
dataSlider = sliderValue;
}
This is the way it should work: the server is always asking for something to printf. I move the slider and send its value, whenever the server calls read().
Problem: the slider doesn't visually move, but its value changes (i can see it in the server's printfs).
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能有两个问题:
您需要调用
setNeedsDisplay
。您正在使用与服务器的同步/阻塞连接。如果您使用同步/阻塞通信,那么一切(包括 UI 更新)都将等到通信结束。如果是这种情况,则使用异步连接。由于断开连接时 UI 会更新,因此这是最有可能出现的问题。
There might be two problems:
You need to call
setNeedsDisplay
.You are using a synchronous/blocking connection with the server. If you use a synchronous/blocking communication then everything, including UI update, will wait until the communication is over. If that is the case then use a asynchronous connection. As the UI is updated when you are disconnected, this is the most probable problem.
嗯..我让它工作了,但是有点滞后:使用的代码是:(在
stream:handleEvent:
方法中)关于如何让它完美工作的想法? Thks
(澄清一下。这里的目的是让 iPod 仅在服务器请求
read()
时发送数据)Hum.. i got it working, but kinda laggy :s the code used was: (in the
stream:handleEvent:
method)Ideas on how to get it working flawlessly? Thks
(Just to be clear. The aim here is for the iPod only send data at the moment the server asks for a
read()
)似乎常量“知道流有可用空间”正在堵塞程序和 UI。我更改了程序的流程以等待来自服务器的消息,只有在此之后它才会发送数据。这里是:
Seems that the constant "knowing that the stream had space available" was clogging the program and UI. I changed the flow of the program to wait for a message from the sever and only after that it would send the data. Here it is: