1
나는 이해하지 못합니다. cellForRowAtIndexPath 함수의 indexPath 매개 변수는 항상 0입니다. 현재 테이블에 7 개의 행이 있습니다. 내 테이블에 표시된 것은 첫 번째 테이블 행의 7 배입니다. 무엇이 indexPath를 항상 0으로 만들 수 있습니까?cellForRowAtIndexPath : indexPath는 항상 0입니다.
@implementation SitesViewController
@synthesize sites, siteCell;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [sites count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SiteCell"];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"SiteCell" owner:self options:nil];
cell = siteCell;
self.siteCell = nil;
}
Site *site = [sites objectAtIndex:indexPath.section];
UILabel *siteNameLabel;
siteNameLabel = (UILabel *)[cell viewWithTag:1];
siteNameLabel.text = site.siteName;
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSManagedObjectContext *context = [[DigMateAppDelegate sharedAppDelegate] managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Sites" inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSError *error;
sites = [context executeFetchRequest:request error:&error];
}
트릭을했다가, 감사합니다! –