0
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"] autorelease];
}
int theRow = indexPath.row;
if(indexPath.section == 0) theRow += 0;
if(indexPath.section == 1) theRow += 3;
if(indexPath.section == 2) theRow += 7;
CountriesAppDelegate *appDelegate = (CountriesAppDelegate *)[[UIApplication sharedApplication] delegate];
CountriesData *country = (CountriesData *)[appDelegate.countries objectAtIndex:indexPath.row];
[[cell primaryLabel] setText:country.countryName];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
我从sqlite数据库填充UITableView
。我有3个部分。从数据库填充UITableView
在的每个部分上面的代码的情况下开始与该数据库的第一个元素。
但我需要的是,每个部分都充满了数据库中的元素,以便作为变量theRow
(3个元素,4个元素,其他元素)。
任何想法?
您使用计算从'appDelegate.countries'为'theRow'值,但是抢值'indexPath.row' .. – 2011-12-22 11:27:01
你的意思是这样'CountriesData *国家=(CountriesData *)的appDelegate。国家objectAtIndex:indexPath.theRow]。 '? – RomanHouse
CountriesData *国家=(CountriesData *)[appDelegate.countries objectAtIndex:theRow];你的问题解决了 –