I want my label to read like this:

Name of Activity

nn%

Instead, here's what appears:

%@

%f%

In addition, I'm getting this warning: Expression result unused

Here's the code I'm trying:

firstLabel.text = @"%@\n%@%",[self.thisSpec activityOfInterest],focusActivityPercent;

[self.thisSpec activityOfInterest] returns a string containing the name of an activity, and focusActivityPercent is a double.

This is the first time I've tried a multiline label.

Any suggestions?

Thanks

有帮助吗?

解决方案

You can't specify string formatting on a string literal on its own like that. In fact, the code you've shown should be producing a syntax error. You have to use NSString's stringWithFormat: class method:

firstLabel.text = [NSString stringWithFormat:@"%@\n%@%",[self.thisSpec activityOfInterest],focusActivityPercent];
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top