ios - 将文本从textview插入到字符串中,在字符串 objective-c 中返回NSMallocBlock

标签 ios objective-c nsstring uitextview

我有一个用户可以编辑的 TextView ,当我尝试将 TextView 中的文本插入到 Nsstring 类型的本地属性时,我得到了这个属性 NSMallocBlock。是什么原因?谢谢你! 这是 cartItemComment 的定义:

@property (nonatomic, assign) NSString * cartItemComment;

这是代码:

CartItem *cartItem = [[CartItem alloc]init];
cartItem.cartItemComment = itemRequestText.text;

cartitem 是一个具有属性 cartItemComment 的对象,在这些行之后,我在 cartItemComment 中得到了 NSMallocBlock。

another problem, i can get a weird string like this:

最佳答案

assign property 属性适用于基本类型,它对对象引用不执行任何操作。当一个对象被分配给这个属性时,它就会被释放(如果它没有被其他对象保留),剩下的只是一个指向它曾经所在的内存的指针。切勿使用分配来存储对象。

weakassign 类似,唯一的区别是当该属性引用的对象被释放时(保留计数达到零),它被设置为 nil,所以你永远不会有一个指向垃圾内存的指针。

strong 保留对象并防止其被释放。

你的属性(property)应该这样声明:

@property (nonatomic, strong) NSString *cartItemComment;

关于ios - 将文本从textview插入到字符串中,在字符串 objective-c 中返回NSMallocBlock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45616779/

相关文章:

ios - 交互式 UIView 翻转过渡

iphone - 显示 UIImagePickerController 后 UITextfields 空白

objective-c - 获取行开头的空格数

ios - InstancesRespondToSelector 在不应该返回 true 时返回 true

ios - 坚持使用 UIActionSheetPicker ,iOS

ios - 如何在 objective-c 框架函数中将可选依赖项的参数作为参数传递

iOS:以编程方式在 UITextView 中向上、向下、向左和向右移动光标

string - NSString 中某个字符出现的次数

objective-c - 如果 NSString 为 NULL,NSInteger 返回 0

ios - 无法确定 UIImageView 帧何时相等