![](/img/trans.png)
[英]iPhone SDK : How to save a image as a file and POST it back to PHP server?
[英]iphone SDK:How use URL to post data back?
我在LightTableViewController.m
讀取了plist數據
我加載這樣的數據:
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 ”和“ status ”發回數據庫
控制打開或關閉哪個燈
這是我發布的方法,它在LightCell0.m
- (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];
}
}
所以...我的問題是
<1>如何回發兩個數據(使用“,”分隔兩個返回變量是否正確?
<2>如何消除錯誤“在非結構體或聯合體中請求成員'plist'”
萬分謝意
1)POST值與URL中的GET值一樣以'&'分隔。
2)“請求成員” ...行告訴您您的成員不存在,或者至少未在此范圍內聲明,警告“ NSString可能沒有響應...”告訴您您正在嘗試調用NSString上的消息/方法,應該在另一個類上調用(NSDictionary是我的猜測)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.