在UILabel中显示indexOfObject

在UILabel中显示indexOfObject,uilabel,type-conversion,Uilabel,Type Conversion,我试图在UILabel中显示NSArray中的对象数,作为UITabelViewCell的一部分: UILabel *numberLabel = (UILabel *)[cell viewWithTag:103]; numberLabel.numberOfLines = [self.inputValues indexOfObject:inputValue]; NSLog(@"rownumber is: %d", numberLabel.numberOfLines); NSLog为我提供了正确的

我试图在
UILabel
中显示
NSArray
中的对象数,作为
UITabelViewCell
的一部分:

UILabel *numberLabel = (UILabel *)[cell viewWithTag:103];
numberLabel.numberOfLines = [self.inputValues indexOfObject:inputValue];
NSLog(@"rownumber is: %d", numberLabel.numberOfLines);

NSLog
为我提供了正确的编号,但标签仅显示默认的标题值。我错过了什么?不会抛出任何错误。

我确信您希望:

UILabel *numberLabel = (UILabel *)[cell viewWithTag:103];
numberLabel.text = [NSString stringWithFormat:@"%d", [self.inputValues indexOfObject:inputValue]];
NSLog(@"rownumber is: %d", numberLabel.numberOfLines);

您需要设置标签的
text
属性。例如:

NSUInteger index = [self.inputValues indexOfObject:inputValue];
numberLabel.text = [NSString stringWithFormat:@"Row %lu", (unsigned long)index];
但是,似乎可以从单元格的索引路径使用
,如下所示:

numberLabel.text = [NSString stringWithFormat:@"Row %ld", (long)indexPath.row];

那么,它应该显示什么呢?你不能在任何地方设置它的文本。。。另外,如果您将标签的高度(以行为单位)设置为
inputValue
?@H2CO3的索引,而我所掌握的信息有限,那么我假设OP将
text
numberOfLines
-查看
NSLog
。真的,虽然,没有进一步澄清的OP,我猜。无论如何,您上次在
UITableViewCell
中使用
numberOfLines
是什么时候?那是我写我的@H2CO3的时候。这是真的-这根本不是(至少是我)每天都做的事情。@JFS“原始海报”。(you)@H2CO3(几乎)这里的每个人都知道如何读和写——但苹果的文档并不是很好的读物——它们往往很枯燥,只是更容易阅读其他内容。谢谢,第二种方法对我来说很好。我以前试过这个,但是错过了
(long)
部分。在iOS上,
NSUInteger
unsigned int
,而
NSInteger
int
,因此可以使用
%u
/
%d
并省略强制转换。但是,在OSX上,
NSInteger
无符号长的
NSInteger
长的
。我有铸造的习惯,这样我就可以在iOS或OSX上使用相同的代码。谢谢!在养成习惯之前,我还需要学习更多。。。