将 NSMutableArray 字符串添加到 UILabel 时程序崩溃 [英] Program crashes when adding NSMutableArray of strings to a UILabel

查看:45
本文介绍了将 NSMutableArray 字符串添加到 UILabel 时程序崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将此字符串数组添加到 summaryText UILabel 时,它崩溃了.请告诉我如何解决这个问题.

When I add this array of strings to the summaryText UILabel it crashes. Please let me know how to fix this.

NSMutableArray *arr = [[NSMutableArray alloc]init];

arr = [Singleton getArray];

NSString *str = [arr componentsJoinedByString:@"\n"];
summaryText.text = str;

这是当我命令单击summaryText时出现的内容

This is what was brought up when i command clicked summaryText

@implementation TotalViewController
@synthesize tax,taxLabel,total,totalLabel,final,finalLabel,fiveLabel,threeLabel,twoLabel,five,three,two, points, pointsLabel,summaryText;

推荐答案

我曾建议 initWithArray,但不清楚为什么不将上面的整个片段替换为:

I had suggested initWithArray, but not clear why you don't replace entire above snippet with:

summaryText.text = [[Singleton getArray] componentsJoinedByString:@"\n"];

但正如其他人指出的那样,您的崩溃并不在这里,这只是简化了您的代码.问题必须在别处解决,可能与 summaryText 的定义/创建有关.如果没有看到崩溃日志或更多代码,很难说.

But as others pointed out, your crash isn't here, this just simplifies your code. The problem has to rest elsewhere, probably related to the definition/creation of summaryText. Hard to say without seeing crash log or more code.

更新:

你说你是在 Interface Builder 中创建了这个控件.您可能需要仔细检查该控件的连接检查器",并确保您的插座设置正确.这听起来很像一个没有在 Interface Builder 中正确设置的控件.或者您可以在 Xcode 中查看您的 .h 文件,它会告诉您它是否已成功链接到 Interface Builder 中的控件.您会在源代码左侧看到一个小圆圈",圆圈中的实心圆点表示您的插座连接正确,空圆圈表示它没有正确连接(例如,在下面的示例中,contactNamecontactAddresscontactPhone 都正确链接,但 myLabel 不是):

You said that you created this control in Interface Builder. You might want to double check your "connections inspector" for that control and make sure your outlet is set up correctly. This sounds a lot like a control that hasn't been set up correctly in Interface Builder. Or you can look at you .h file in Xcode and it will tell you if it's successfully linked to a control in Interface Builder. You'll see a little "circle" to the left of the source code, a solid dot in the circle means that your outlet is hooked up correctly, and empty circle means that it's not (e.g. in this example below, contactName, contactAddress, and contactPhone are all linked up correctly, but myLabel is not):

这篇关于将 NSMutableArray 字符串添加到 UILabel 时程序崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆