0

我有这个方法:

- (void) voteResult: (NSString *)partyName votedNumber:(int)votedNumber
{
    int *moreVotes;
    moreVotes = 2000 - votedNumber;

    _labelVoteResult.text = @"Currently, your party (%x) has %i votes. We need %i more votes to put %x on our list. Share to your Facebook or Twitter to get more votes from your downline or upline.", partyName, votedNumber, moreVotes, partyName;
}

但我收到此错误消息:

Incompatible integer to pointer conversion assigning to 'int *' from 'int'

因为这条线:

moreVotes = 2000 - votedNumber;

我也有这个错误信息:

Expression result unused

因为这一行 ( partyName) :

_labelVoteResult.text = @"Currently, your party (%x) has %i votes. We need %i more votes to put %x on our list. Share to your Facebook or Twitter to get more votes from your downline or upline.", partyName, votedNumber, moreVotes, partyName;

最后一件事,%x 应该是一个字符串,但 Objective C 只有 %i 代表整数,%c 代表字符。我不知道字符串到底是什么。

谢谢你。

4

1 回答 1

3

该方法应如下所示:

- (void) voteResult: (NSString *)partyName votedNumber:(int)votedNumber
{
    // Not int*
    int moreVotes = 2000 - votedNumber;

    // Use [NSString stringWithFormat:] with partyName using the %@ format specifier
    _labelVoteResult.text = [NSString stringWithFormat:@"Currently, your party (%@) has %i votes. We need %i more votes to put %@ on our list. Share to your Facebook or Twitter to get more votes from your downline or upline.", partyName, votedNumber, moreVotes, partyName);

}
于 2013-09-16T10:35:48.037 回答