iphone SDK:如何使用URL发回数据?
我在LightTableViewController.m上读取了plist数据 我加载的数据如下:iphone SDK:如何使用URL发回数据?,iphone,url,post,sdk,Iphone,Url,Post,Sdk,我在LightTableViewController.m上读取了plist数据 我加载的数据如下: LOG RESULT: The Plist Data Is : ( { category = 11; id = 1; name = "LIVING RM"; status = 0; }, { category = 11; id = 2;
LOG RESULT:
The Plist Data Is : (
{
category = 11;
id = 1;
name = "LIVING RM";
status = 0;
},
{
category = 11;
id = 2;
name = "BEDROOM RM";
status = 0;
}
)
我需要将id和状态发回数据库
控制打开或关闭哪个灯的步骤
这部分是my post方法,在LightCell0.m中
所以…我的问题是
如何将两个数据发回使用是否正确,将两个返回变量分开
如何消除非结构或联合中成员“plist”的错误请求
非常感谢1类似于URL中的GET值,POST值由“&”分隔
2“成员请求”。。。行告诉您您的成员不存在,或者至少未在此范围内声明,警告“NSString可能没有响应…”告诉您正在尝试调用NSString上的消息/方法,我猜应该在另一个类上调用该消息/方法。NSDictionary是我的猜测。我认为在这个空白处,plist为null。我将此添加到lightCell0:NSURLRequest*theRequest=[nsurlRequestWithURL:[NSURLWithString:@cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];NSData*returnData=[NSURLConnection sendSynchronousRequest:theRequest returningResponse:nil错误:nil];NSString*listFile=[NSString alloc]initWithData:returnData encoding:NSASCIIStringEncoding];self.plist=[listFile propertyList];但我得到了[[self.plist objectAtIndex:indexath.row]valueForKey:@id是97534704或一个随机数……不是我定义的真实id。哦,我明白了,我忘了添加intValue
- (void)switchToggled:(id)sender {
UISwitch *theSwitch = (UISwitch *)sender;
UITableViewCell *cell = (UITableViewCell *)theSwitch.superview.superview;
UITableView *tableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [tableView indexPathForCell:cell];
if(theSwitch.on) {
NSURL * url;
NSMutableURLRequest * request;
NSString *_urlString = @"http://10.85.28.99/req_light.php";
url = [self smartURLForString:_urlString];
request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
//This is my first post method,it is static,only get the indexPath,Not a real id and status I want to post back
NSString *post = [NSString stringWithFormat:@"lightcb%i=1", indexPath.row+1];
NSData *postData = [ NSData dataWithBytes: [ post UTF8String ] length: [ post length ] ];
[request setHTTPBody:postData];
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
}
else {
NSURL * url;
NSMutableURLRequest * request;
NSString *_urlString = @"http://10.85.28.99/req_light.php";
url = [self smartURLForString:_urlString];
request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
//I got one error and one warring
//Error is "Request for member 'plist' in something not a structure or union"
//Warning is 'NSString' may not resopnd to '+stringWithFormat:value=ForKey'
NSString *post = [ NSString stringWithFormat:@"id=%i,status=0",
[[self.plist objectAtIndex:indexPath.row] valueForKey:@"id"]];
NSData *postData = [ NSData dataWithBytes: [ post UTF8String ] length: [ post length ] ];
[request setHTTPBody:postData];
self.connection = [NSURLConnection connectionWithRequest:request delegate:self];
}
}