gpt4 book ai didi

ios - 在方法上计算给定数字会出现此错误

转载 作者:行者123 更新时间:2023-11-28 20:14:06 24 4
gpt4 key购买 nike

我有这个方法:

- (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 表示字符。我不知道字符串到底是什么。

谢谢。

最佳答案

方法应该是这样的:

- (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);

}

关于ios - 在方法上计算给定数字会出现此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18825916/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com