所以我最初开始使用iOS 5的基于选项卡的应用程序模板.我有一个标签栏连接到两个视图,但是当我去向firstviewcontroller添加一个Table View Controller时,它不会让我.
我对如何解决这个问题感到困惑?我必须用代码吗?或者有没有办法以图形方式做到这一点?
我遇到了这段代码的问题:
for (int i = 0; i < [tempInviteeArray count]; i++)
{
NSArray *tempContact = [tempInviteeArray objectAtIndex:i];
NSDictionary *tempContactDictionary = [tempContact objectAtIndex:1];
int tempContactDelay = [[tempContact objectAtIndex:2] intValue];
FlokContact *tempContact = [[FlokContact alloc] initWithJSONData:tempContactDictionary andDelay:tempContactDelay];
}
Run Code Online (Sandbox Code Playgroud)
最后一行抛出一个错误:
"Redefinition of 'tempContact' with a different type
Run Code Online (Sandbox Code Playgroud)
initWithJSONData:接受NSDictionary和Delay:int
我试图重写这个代码,不同的类型和所有,我只是不知道我在做什么
基本上我写了一个 NSData 对象:
[asyncSocket writeData:JSONRequestData withTimeout:-1 tag:1];
Run Code Online (Sandbox Code Playgroud)
当运行时,调用委托
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
Run Code Online (Sandbox Code Playgroud)
但由于某种原因,当写入到缓冲区时......它没有写出到服务器。
当我停止构建时,我猜套接字决定写入所有内容,并且服务器最终会看到它。
我该如何解决这个问题?没有办法刷新 CocoaAsyncSocket,因为它没有必要...我尝试添加行结尾,例如“/n”等,但这也没有任何作用。
所以这就是问题:流不是在正确的时间写入,而是无法从我的服务器获得响应.我知道我正在编写正确的数据,因为当我停止构建时,它会写入服务器并且服务器很高兴.我很困惑为什么这不是在正确的时间发生的.
我正在使用GCDAsyncSocket来读/写套接字
我已经创建了一个单独的类来处理所有网络,这是我的代码:
-(id)init{
self = [super init];
if (self) {
asyncSocket = [[GCDAsyncSocket alloc] initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
NSError *error = nil;
if (![asyncSocket connectToHost:@"localhost" onPort:8888 error:&error]) // Asynchronous!
{
// If there was an error, it's likely something like "already connected" or "no delegate set"
NSLog(@"I goofed: %@", error);
}
}
return self;
}
//GCD Async Delegate Methods
- (void)socket:(GCDAsyncSocket *)sender didConnectToHost:(NSString *)host port:(UInt16)port
{
NSLog(@"socket:%p didConnectToHost:%@ port:%hu", sender, host, port);
NSLog(@"Cool, I'm connected! That was easy.");
}
- (void)socket:(GCDAsyncSocket …Run Code Online (Sandbox Code Playgroud) 我正在创建一个看起来像的JSON字符串:
{ "request_type":"send_string", "security_level":0, "device_type":"ios", "blob":{"string":"blah"}"}
Run Code Online (Sandbox Code Playgroud)
这就是我做的:
NSDictionary *requestData = [NSDictionary dictionaryWithObjectsAndKeys:
@"send_string",@"request_type",
[NSNumber numberWithInt:0],@"security_level",
@"ios",@"device_type",
//No Email Provided, This is just for testing
blobData,@"blob",
nil];
NSData *JSONRequestData = [NSJSONSerialization dataWithJSONObject:requestData options:kNilOptions error:&error];
Run Code Online (Sandbox Code Playgroud)
当我用NSLog打印出来时,我明白了
{"security_level":"0","request_type":"send_string","device_type":"ios","blob":{"string":"hello"}}
Run Code Online (Sandbox Code Playgroud)
它出了故障...给出了什么?