尝试连接字符串时,无法静态分配接口类型

时间:2012-03-11 18:08:45

标签: objective-c

这是我的代码:

- (BOOL) saveSiteData  {

    //  validate all fields
    if(txtSiteID.text.length == 0 || txtSiteDesc.text.length == 0)  {
        [self Alert:@"Missing Site ID and/or Description" andData:@"Reqired fields"];
        return NO;
    }

    if(txtSTA.text.length == 0 || txtElev.text.length == 0)  {
        [self Alert:@"Missing Initial STA and/or Elevation" andData:@"Reqired fields"];        
        return NO;
    }

//    txtSiteDesc.text = txtSiteDesc.text.re  <----------  remove single quotes  TODO

    NSString selectCmd = [NSString stringWithFormat:@"%@,%@,%@", @"SELECT COUNT (*) FROM SiteData WHERE SITE_ID = '",
                          txtSiteID.text, @"'"];
    return YES;
}

我得到的错误信息是:无法静态分配接口类型。

为什么呢?以及如何修复它?

1 个答案:

答案 0 :(得分:5)

NSString selectCmd = [NSString stringWithFormat:@"%@,%@,%@", @"SELECT COUNT (*) FROM SiteData WHERE SITE_ID = '", txtSiteID.text, @"'"];

这是错误的。任何Objective-C对象都是指针。所以你需要一个星号:

NSString *selectCmd = etc...