2014-09-03 63 views
-2

我在'名稱'中有一個名稱數組。我試圖在用戶點擊表格單元格時顯示警報。如果用戶觸摸第一個單元格,[名稱objectatindex:0]應該是警報視圖中的消息。這是我所做的無法將變量傳遞到警報視圖

UIAlertView *okAlert = [[UIAlertView alloc] initWithTitle:@"ok" message:@"You have just tapped [names objectatindex:0]" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; 

    okAlert.tag=0; 


    [okAlert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO]; 

在消息中它沒有顯示名稱。我無法弄清楚問題所在。你能幫我解決嗎?

在此先感謝。

+1

閱讀有關'的NSString stringWithFormat:'。 – rmaddy 2014-09-03 16:41:52

回答

3

試試這個:

UIAlertView *okAlert = [[UIAlertView alloc] initWithTitle:@"OK" 
                message:[NSString stringWithFormat:@"You have just tapped %@.", [names objectAtIndex:0]] 
               delegate:self 
             cancelButtonTitle:@"No" 
             otherButtonTitles:@"Yes", nil]; 
0
message:@"You have just tapped [names objectatindex:0]" 

您已經隱藏一個字符串常量內部的代碼。現在它只是字母。

嘗試:

UIAlertView *okAlert = [[UIAlertView alloc] initWithTitle:@"ok" 
    message:[@"You have just tapped " stringByAppendingString:names.firstObject] 
    delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];