2011-12-22 3 views
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 채우기

위 코드의 경우 각 섹션은 데이터베이스의 첫 번째 요소로 시작합니다.
하지만 각 섹션에는 datebase 요소가 순서대로 변수 theRow (요소 3 개, 요소 4 개, 기타 요소)로 채워져 있어야합니다.

아이디어가 있으십니까?

+0

이 사용 appDelegate.countries''에서'theRow' 가치 만 잡아 값을 계산'indexPath.row' ... –

+0

당신이'CountriesData * 국가 = (CountriesData *) [AppDelegate에 같은 것을 의미한다. 국가 objectAtIndex : indexPath.theRow]; '? – RomanHouse

+0

CountriesData * country = (CountriesData *) [appDelegate.countries objectAtIndex : theRow]; 당신의 문제는 –

답변

0
CountriesData *country = (CountriesData *)[appDelegate.countries objectAtIndex: theRow]; 
관련 문제