我試圖讓一個警告框顯示一個隨機生成的數字,但不管我怎麼玩,我還沒有得到它的工作,我仍在網上搜索。下面是我有:不兼容的指針類型發送'nsnumber *'到類型'nsstring *'的參數
ticketNumber = [NSNumber numberWithInt:arc4random() %100000];
PFObject *people = [PFObject objectWithClassName:@"People"];
people[@"ticket"] = ticketNumber;
people[@"photo"] = chosenImage;
[people saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (succeeded) {
// The object has been saved.
UIAlertView *ticketNumberView = [[UIAlertView alloc] initWithTitle:@"Ticket Number"
message:ticketNumber
delegate:nil
cancelButtonTitle:@"OK, I got it."
otherButtonTitles: nil];
[ticketNumberView show];
不過,我收到的錯誤是「不兼容的指針類型發送‘的NSNumber *’到類型的參數‘的NSString *’」。該應用程序仍然編譯並在我的iPhone上運行,但當它下降到該代碼區域時,它會凍結並崩潰。我在這裏有什麼錯誤?
您正在將NSString值作爲NSNumber ...您必須將字符串值轉換爲數字。 – Manthan 2015-02-11 09:26:41