ios - 整数到指针的转换不兼容。 iOS, objective-c

标签 ios type-conversion

我遇到了这个错误

Incompatible integer to pointer conversion assigning to NSString from int

但我不理解以下代码的概念:

int counts;
counts = self.notificationarray.count;
title.text = (@"Notifications %i", counts );

最佳答案

替换:

title.text = (@"Notifications %i", counts );

与:

title.text = [NSString stringWithFormat:@"Notifications %i", counts];

因为您当前拥有的代码根本没有执行您想要的操作。我猜它正在为标题文本分配一个字符串(@"Notifications %i"),然后尝试接下来分配一个整数(counts)。您想要做的是创建一个具有格式的字符串并将其设置为标题文本。

关于ios - 整数到指针的转换不兼容。 iOS, objective-c ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22465565/

相关文章:

ios - 如何根据调用其他函数的次数来操作开关函数?

ios - Xamarin WebView iOS检测滚动事件

c# - 从 float 中获取 int 的正确方法是什么?

C# Dynamics : Convert. ChangeType 与 Cast

c# - 动态生成的 IL 中的值类型转换

ios - ios 7 UITableViewController Clear on Appearance 是否损坏(来自 Storyboard)?

html - Safari 中的导航栏堆栈

ios - 将文本从 UItableViewcell 选择传递到 UItextfield

javascript - 在 JavaScript 中,我应该调用 parseFloat 将字符串转换为 float ,还是应该让 JavaScript 转换它们?

type-conversion - COBOL 数据类型转换 : Convert date in DDMMYY to a packed decimal of 3-bytes