我從服務器使用php腳本獲取問題。我根據問題的數量設置單元格的數量,但是當我寫入單元格時,它只輸出1個問題。如果我使用for循環,單元格是空白的,但是如果我設置了數字,它會根據數據庫中有多少個問題重複相同的問題。下面是代碼:如何設置表格目標中的每個單元格的文本c
NSString *numOfQuestionsURL = @"http://**.***.**.**/count.php";
NSData *dataURLforSize = [NSData dataWithContentsOfURL:[NSURL URLWithString: numOfQuestionsURL]];
NSString *serverOutputforSize = [[NSString alloc] initWithData:dataURLforSize encoding:NSASCIIStringEncoding];
int numOfQuestions = [serverOutputforSize intValue];
for(int i = 0; i <= numOfQuestions; i++)
{
_hostStr = @"http://**.***.**.**/getQuestion.php?num=";
_appendString = [[NSNumber numberWithInt:i] stringValue];
_hostStr = [_hostStr stringByAppendingString: _appendString];
}
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString: _hostStr]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding:NSASCIIStringEncoding];
result.textLabel.text = serverOutput;
_appendString = [[NSNumber numberWithInt:i] stringValue];是你告訴劇本你想要檢索什麼問題的地方。
你在哪裏添加此代碼? – Mohith 2013-05-09 07:18:38
如果這在cellForRowAtIndexPath中,則除去for循環並添加_appendString = [[NSNumber numberWithInt:indexPath.row] stringValue]; – Mohith 2013-05-09 07:19:29
它在cellForRowAtIndexPath中,但沒有奏效,單元格仍然空白 – heinst 2013-05-09 07:25:30