The following code is making my app crash at line 3 without an error I would recognize or know how to deal with. Any ideas as to what I am doing wrong?
NSInteger *match = [str1 intValue] + [str2 intValue];
NSString *strrep = [NSString stringWithFormat:开发者_C百科@"%i", match];
label.text = [strrep substringWithRange:NSMakeRange(1,3)];
I suggest you break line 3 into two lines, in order to isolate the issue.
NSString *result = [strrep substringWithRange:NSMakeRange(1,3)];
label.text = result;
If I had to guess, I'd say label has probably been released somewhere, and you are trying to assign to a bad location.
You want NSInteger match
. No pointer. (NSInteger is not a class, it is just a typedef for int
or long
depending on your compilation target.)
Although, bizarrely, you code will probably still actually work like this, since the pointer itself will act in place of the int.
If your string is less than (1 + 3) 4 characters long, this will crash.
精彩评论