2013-10-04 56 views
1

我有一个iOS 6应用程序,我正在使用StoryBoard中的Xcode 5转换为iOS 7。一切工作正常,直到我决定我想添加一个自定义的UITableViewCell后,将应用程序转换为iOS 7的桌面控制器。我创建了通常的代码来做到这一点,但是当我运行该应用程序时,它给出了一个意外的结果,它只是显示内容的一个单元格行,它在桌面视图之上浮动,显示了它后面显示的空单元行。当我滚动表格行时,我会看到它们在后台滚动,并且滚动时会在一个视图单元格行中显示的数据发生更改(请参见附图)。但是,如果我点击看起来像空行的东西,它可以正常工作,并且正确地继续到详细视图控制器。我在我的另一台MacBook上使用Xcode 4.6对iOS 6中的应用进行了相同的更改,并且它可以正常工作(请参阅附图)。所以我在考虑iOS 7处理uitableviewcell类的方式不同于iOS 6,或者我在iOS 7应用程序的代码中犯了一个错误,而没有意识到它。iOS 7 UITableViewCell问题

这里是不是正常工作了iOS 7的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *cellIdentifier = @"Cell"; 

    ExhibitorsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (!cell) { 
     cell = [[ExhibitorsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    if (tableView == self.myTableView){ 
    NSManagedObject *object = [self.objects objectAtIndex:indexPath.row]; 
    cell.nameLabel.text = [object valueForKey:@"name"]; 
    NSString * booth = [NSString stringWithFormat:@"Booth Number: %@", [object valueForKey:@"boothLabel"]]; 
    cell.boothNumberLabel.text = booth; 
    } 
    else{ 
    NSManagedObject *object = [results objectAtIndex:indexPath.row]; 
    cell.nameLabel.text = [object valueForKey:@"name"]; 
    NSString * booth = [NSString stringWithFormat:@"Booth Number: %@", [object valueForKey:@"boothLabel"]]; 
    cell.boothNumberLabel.text = booth; 
    } 

    return cell; 
} 

这里是工作(对我来说似乎是相同的,但我想我需要其他的眼睛才能看到的iOS 6的代码):

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath 
{ 
    static NSString *simpleTableIdentifier = @"Cell"; 


    ExhibitorsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 


    if (!cell) { 
     cell = [[ExhibitorsViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
     cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    } 

    if (tableView == self.myTableView){ 
    NSManagedObject *object = [self.objects objectAtIndex:indexPath.row]; 
    cell.nameLabel.text = [object valueForKey:@"name"]; 
    NSString * booth = [NSString stringWithFormat:@"Booth Number: %@", [object valueForKey:@"boothLabel"]]; 
    cell.boothNumberLabel.text = booth; 
    } 
    else{ 
    NSManagedObject *object = [results objectAtIndex:indexPath.row]; 
    cell.nameLabel.text = [object valueForKey:@"name"]; 
    NSString * booth = [NSString stringWithFormat:@"Booth Number: %@", [object  valueForKey:@"boothLabel"]]; 
    cell.boothNumberLabel.text = booth; 
    } 

    return cell; 
} 

Here是iOS 7应用程序中正在发生的事情的屏幕截图。

Here是它应该看起来像(这是我做了自定义UITableViewCell更改之前)。

+0

所以我重新创建了视图控制器和自定义视图单元格,以查看从头开始将解决问题。它没有。但这一切似乎都指向了Xcode 5故事板,以及它如何在自定义的uitableviewcell中展示视图。它正在做一些奇怪的事情。它正在创建单元格并正确链接链接到uilabel iboutlets的单元格属性,但视单元格布局未正确包含uilabels。这就像在tableview上面有另一个视图,它将uilabels放在视图中,所以它们看起来像是浮在桌面上的视图中。 – bachma0507

回答

0

我想通了。我不得不将uilabel拖到uitableviewcell上方一点,直到我看到突出显示的单元格边界。这将标签放置在单元格上方。然后我必须将标签移回视单元。从来没有必要在xcode 4.6中做到这一点。但是,哦,哦。