Program crashes when adding NSMutableArray of strings to a UILabel

二次信任 提交于 2020-01-07 08:49:12

问题


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;

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;

回答1:


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

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

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.

Update:

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):



来源:https://stackoverflow.com/questions/11285927/program-crashes-when-adding-nsmutablearray-of-strings-to-a-uilabel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!