-1
我有從遠程數據庫中獲取的字符串列表,它們顯示正常。然後,當我添加一個字符串時,新的字符串被添加到數據庫中,但是當它顯示在屏幕上時,它出於某種原因顯示了第一個和第二個項目中的第一個項目的值。ios - 無法弄清楚爲什麼項目列表顯示添加新項目時第一個和最後一個點的第一個項目的值
下面是我在做什麼:
// CREATING EACH CELL IN THE LIST
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"business";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17];
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
}
cell.textLabel.text = [cellTitleArray objectAtIndex:indexPath.row];
// CLOSE THE SPINNER
[spinner stopAnimating];
// return the cell for the table view
return cell;
}
當數據從數據庫中檢索,這裏是我做的:
dispatch_sync(dispatch_get_main_queue(), ^{
items_array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
if(!error){
[self loadTitleStrings];
}
[self.itemList reloadData];
});
這裏是被稱爲
的loadTitleStrings-(void)loadTitleStrings
{
if(!standardUserDefaults)
standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *is_private = [standardUserDefaults objectForKey:@"is_private"];
if(!cellTitleArray)
{
cellTitleArray = [NSMutableArray array];
}
for(NSDictionary *dictionary in items_array)
{
NSString *tcid = [dictionary objectForKey:@"comment_id"];
[theArray addObject:tcid];
NSString *string;
if(!is_private || [is_private isEqualToString:@"0"])
{
string = [NSString stringWithFormat:@"%@: %@", [dictionary objectForKey:@"first_name"], [dictionary objectForKey:@"comment"]];
}
else
{
string = [NSString stringWithFormat:@"%@", [dictionary objectForKey:@"comment"]];
}
[cellTitleArray addObject:string];
}
}
任何人都可以知道爲什麼最後一項顯示的值是第一個?我真的很難過!
謝謝!