1

我正在遵循 Alasdair Allan 第 91 页的 Learning iOS Programming 第 2 版书中的代码。我正在尝试将表格视图输出信息到文本视图。在我添加此代码之前,其他一切都有效。delegate.cities 引用了 AppDelegate 中称为城市的 NSMutableArray。

我认为这可能与objectAtIndex期望NSUInteger有关,但书上说要发送它index.rowindexNSIndexPath类型,它在我导入到此类的 SimpleView 类中。rowNSInteger类型,所以我假设问题是这本书希望我在 期望无符号整数时向objectAtIndex发送有符号整数。会不会是他的问题?如果是这样,我该如何解决?

错误消息:成员引用基类型 'char (const char ,int)' 不是结构或联合

这是我的功能:

-(void)viewDidLoad
{
    [super viewDidLoad];

    AppDelegate *delegate = 
            (AppDelegate *)[[UIApplication sharedApplication] delegate];

    City *thisCity = [delegate.cities objectAtIndex:index.row]; //error with index.row

    self.title = thisCity.cityName;
}
4

1 回答 1

2

index()系统标头中的全局函数string.h使用类似于错误 ( char* (const char*, int)) 的签名来定义。编译器似乎认为您正在尝试将该函数作为结构或联合来访问(即通过使用.row它,这是您可以对结构执行的操作)。

显然,您的类中没有命名字段index(您没有显示该类,所以我猜),或者编译器以某种方式错误地解决了它。要么使用正确的字段名称,要么使用类似self->index.row.

于 2012-07-29T20:22:26.007 回答