为什么我在 objectForKey 方法中收到警告?

Why I receive warning in objectForKey method?

我需要在

中执行方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

我有一个 NSDictionary,我想从中获取 ID(长)并将其发送到我的方法:

    long sect = (long)section;
    [objectp.methodA countRowsInSection:[tableSections objectForKey:[NSString stringWithFormat:@"%ld", sect]]]

我收到警告:

Incompatible pointer to integer conversion sending 'id' to parameter of type 'long'

为什么?

我尝试将 NSInteger 转换为 long,然后再转换为 NSString,但警告仍然存在。

备注: countRowsInSectionlong.

我在 NSDictionary 中将数据存储为 NSString:

[tableSections setValue:[NSString stringWithFormat:@"%ld", newCategoryID]
   forKey:[NSString stringWithFormat:@"%ld", counter]];

I have an NSDictionary from which I want to get ID (long) and send it to my method:

不,你不想从字典中获取类型为long的ID,因为long是C类型,不能存储在字典中。它可能是 NSStringNSNumber 的实例。然后你将它作为 -countRowsInSection: 的参数,它可能需要 NSIntegerlong,因此是 C 类型。

您的 countRowsInSection: 似乎期望它的参数是 long。但是您要向它发送一个对象(可能是 NSNumber)。如果是这种情况,以下将起作用:

[objectp.methodA countRowsInSection:[[tableSections objectForKey:[NSString stringWithFormat:@"%ld", sect] longValue]]];