3

我将 a 嵌入UITableView到子类UIViewController中。这UITableView使用带有图像和文本的单个动态原型,这两者都可以根据加载到其中的内容而有所不同。我遇到的问题是绝对没有UITableView出现在 subclassed 上UIViewControllerUITableView本身似乎没有出现。

我在子类中创建了一个IBOutlet,如下所示:UITableViewUIViewController

@property (weak, nonatomic) IBOutlet UITableView *functionTableView;

正确链接回UITableView.

viewDidLoad父级的方法中,UIViewController我有以下代码:

self.functionTableView.delegate = self;
self.functionTableView.dataSource = self;
[self.functionTableView reloadData];

我也为班级声明了代表。我正在使用的数据源目前是一个NSMutableArray包含数据的对象。我已经实现了UITableViewDataSourceUITableViewDelegate方法如下:

#pragma mark - Table view data source delegate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    NSLog(@"tableView:numberofRowsInSection %u", [[EmulatorModel sharedEmulatorModel].currentFunctionBank count]);
    return [[EmulatorModel sharedEmulatorModel].currentFunctionBank count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Updating Cell %d", indexPath.row);
    NSLog(@"For Function %@", [EmulatorModel sharedEmulatorModel].currentFunctionBank[indexPath.row]);
    static NSString *CellIdentifier = @"FunctionCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    LivioFunction *func = nil;
    if ([EmulatorModel sharedEmulatorModel].currentFunctionBank[indexPath.row] != [NSNull null]) {
        func = [EmulatorModel sharedEmulatorModel].currentFunctionBank[indexPath.row];
        NSLog(@"Cell Text: %@", func.label);
        cell.textLabel.text = func.label;
        NSLog(@"Cell Image %@", func.artwork);
        cell.imageView.image = func.artwork;
    } else {
        cell.textLabel.text = @" ";
        cell.imageView.image = [UIImage imageNamed:@"HD_fav.png"];
    }

    NSLog(@"cell: %@", cell);

    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Table view row selected: %d", indexPath.row);
    if ([EmulatorModel sharedEmulatorModel].currentFunctionBank[indexPath.row]) {
        id fn = nil;
        fn = ([EmulatorModel sharedEmulatorModel].currentFunctionBank)[indexPath.row];

        if (fn && [fn isKindOfClass:[LivioFunction class]]) {
            LivioFunction *function = (LivioFunction*)fn;
            if (function.functionID == indexPath.row && function.type == LVCFunctionTypeMenu) {
                [self resetButtonImages];
                [self resetButtonLabels];
            }
        }

        [LivioConnectLib sendUserSelect:indexPath.row inputType:LVCInputTypeFunction];
    }
}

NSLog's正在吐出正确的数据,而我在其中使用的重新加载数据导致viewDidLoad数据源delegate方法被调用。所以我在第一次尝试 iOS UI 时感到困惑和沮丧。想法?

编辑:请求 lldb 调试器输出到po [[UIApp keyWindow] recursiveDescription]

(id) $0 = 0x0018c7d0 <UIWindow: 0xde9e830; frame = (0 0; 768 1024); layer = <UIWindowLayer: 0xde9a9d0>>
| <UILayoutContainerView: 0xde9fa30; frame = (0 0; 768 1024); transform = [0, -1, 1, 0, 0, 0]; autoresize = W+H; layer = <CALayer: 0xde9fab0>>
|    | <UINavigationTransitionView: 0xde9fdc0; frame = (0 0; 1024 768); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0xde9fe40>>
|    |    | <UIViewControllerWrapperView: 0x182430; frame = (0 64; 1024 704); autoresize = RM+BM; layer = <CALayer: 0x17f4e0>>
|    |    |    | <UIView: 0xdedf2c0; frame = (0 0; 1024 704); autoresize = RM+BM; layer = <CALayer: 0xdedf2f0>>
|    |    |    |    | <UIImageView: 0xdedf320; frame = (0 0; 1024 704); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xdedf360>>
|    |    |    |    | <AutoScrollLabel: 0xdedecd0; baseClass = UIScrollView; frame = (433 386; 366 48); text = 'Livio Emulator'; clipsToBounds = YES; autoresize = RM; userInteractionEnabled = NO; layer = <CALayer: 0xdedeb80>; contentOffset: {0, 0}>
|    |    |    |    |    | <UILabel: 0xdedef20; frame = (81.5 5; 203 38); text = 'Livio Emulator'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0xdedef90>>
|    |    |    |    |    | <UILabel: 0xdedefc0; frame = (283 5; 203 38); text = 'Livio Emulator'; clipsToBounds = YES; hidden = YES; userInteractionEnabled = NO; layer = <CALayer: 0xdedf110>>
|    |    |    |    |    | <UILabel: 0xdedf140; frame = (566 5; 203 38); text = 'Livio Emulator'; clipsToBounds = YES; hidden = YES; userInteractionEnabled = NO; layer = <CALayer: 0xdedf290>>
|    |    |    |    | <UIImageView: 0xdedd820; frame = (733 169; 67 25); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xdedd640>>
|    |    |    |    | <UIImageView: 0xdeddb90; frame = (524 200; 175 178); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xdedd700>>
|    |    |    |    | <UILabel: 0xdedf1b0; frame = (432 431; 368 27); text = 'Connect an app '; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0xdedc440>>
|    |    |    |    | <UIButton: 0xdede910; frame = (57 169; 100 52); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0xdede9a0>>
|    |    |    |    |    | <UIButtonLabel: 0xdedeab0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xdedeb20>>
|    |    |    |    | <UIButton: 0xdede070; frame = (57 229; 100 50); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0xdede000>>
|    |    |    |    |    | <UIButtonLabel: 0xdede100; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xdede030>>
|    |    |    |    | <UIButton: 0xdedf3e0; frame = (325 455; 368 38); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0xdedf4d0>>
|    |    |    |    |    | <UIButtonLabel: 0xdedf590; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xdedf600>>
|    |    |    |    | <UIButton: 0xdedf650; frame = (325 487; 368 34); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0xdedf780>>
|    |    |    |    |    | <UIButtonLabel: 0xdedf7f0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xdedf860>>
|    |    |    |    | <UITableView: 0xe97d800; frame = (226 164; 276 338); clipsToBounds = YES; alpha = 0; opaque = NO; autoresize = W+H; layer = <CALayer: 0xdede2c0>; contentOffset: {0, 0}>
|    |    |    |    |    | <UITableViewCell: 0xdedfbc0; frame = (0 308; 276 44); text = ' '; autoresize = W; layer = <CALayer: 0xdedf090>>
|    |    |    |    |    |    | <UITableViewCellContentView: 0xdedfcc0; frame = (0 0; 276 43); layer = <CALayer: 0xdedf0c0>>
|    |    |    |    |    |    |    | <UIImageView: 0xdedfd00; frame = (0 0; 43 43); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0xdedfd40>>
|    |    |    |    |    |    |    | <UILabel: 0xdee01b0; frame = (53 0; 213 43); text = ' '; clipsToBounds = YES; layer = <CALayer: 0xdee0220>>
|    |    |    |    |    |    | <UIView: 0xdedfdc0; frame = (0 43; 276 1); autoresize = W+TM; layer = <CALayer: 0xdedfdf0>>
|    |    |    |    |    | <UITableViewCell: 0x197220; frame = (0 264; 276 44); text = ' '; autoresize = W; layer = <CALayer: 0x197320>>
|    |    |    |    |    |    | <UITableViewCellContentView: 0x196b50; frame = (0 0; 276 43); layer = <CALayer: 0x196b90>>
|    |    |    |    |    |    |    | <UIImageView: 0x196bc0; frame = (0 0; 43 43); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x19b0d0>>
|    |    |    |    |    |    |    | <UILabel: 0x19cf90; frame = (53 0; 213 43); text = ' '; clipsToBounds = YES; layer = <CALayer: 0x19d000>>
|    |    |    |    |    |    | <UIView: 0xdeddf90; frame = (0 43; 276 1); autoresize = W+TM; layer = <CALayer: 0xdeddfc0>>
|    |    |    |    |    | <UITableViewCell: 0xdedd100; frame = (0 220; 276 44); text = ' '; autoresize = W; layer = <CALayer: 0xdedd200>>
|    |    |    |    |    |    | <UITableViewCellContentView: 0xdedd060; frame = (0 0; 276 43); layer = <CALayer: 0xdedd230>>
|    |    |    |    |    |    |    | <UIImageView: 0xdedd260; frame = (0 0; 43 43); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0xdedd2a0>>
|    |    |    |    |    |    |    | <UILabel: 0xdeddc40; frame = (53 0; 213 43); text = ' '; clipsToBounds = YES; layer = <CALayer: 0xdeddcf0>>
|    |    |    |    |    |    | <UIView: 0xdedf060; frame = (0 43; 276 1); autoresize = W+TM; layer = <CALayer: 0xdeddf60>>
|    |    |    |    |    | <UITableViewCell: 0xdedcd70; frame = (0 176; 276 44); text = ' '; autoresize = W; layer = <CALayer: 0xdea80d0>>
|    |    |    |    |    |    | <UITableViewCellContentView: 0xdedd5a0; frame = (0 0; 276 43); layer = <CALayer: 0xdedd750>>
|    |    |    |    |    |    |    | <UIImageView: 0xdedf9b0; frame = (0 0; 43 43); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0xdedd780>>
|    |    |    |    |    |    |    | <UILabel: 0xdedbdc0; frame = (53 0; 213 43); text = ' '; clipsToBounds = YES; layer = <CALayer: 0xded9e10>>
|    |    |    |    |    |    | <UIView: 0xdedd0d0; frame = (0 43; 276 1); autoresize = W+TM; layer = <CALayer: 0xdedf030>>
|    |    |    |    |    | <UITableViewCell: 0x19fc80; frame = (0 132; 276 44); text = ' '; autoresize = W; layer = <CALayer: 0x19fd80>>
|    |    |    |    |    |    | <UITableViewCellContentView: 0x18f4b0; frame = (0 0; 276 43); layer = <CALayer: 0x19d680>>
|    |    |    |    |    |    |    | <UIImageView: 0x191b20; frame = (0 0; 43 43); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x19d6b0>>
|    |    |    |    |    |    |    | <UILabel: 0x1934b0; frame = (53 0; 213 43); text = ' '; clipsToBounds = YES; layer = <CALayer: 0x1975e0>>
|    |    |    |    |    |    | <UIView: 0xdedfa20; frame = (0 43; 276 1); autoresize = W+TM; layer = <CALayer: 0xdedd0a0>>
|    |    |    |    |    | <UITableViewCell: 0x1931b0; frame = (0 88; 276 44); text = ' '; autoresize = W; layer = <CALayer: 0x18ec60>>
|    |    |    |    |    |    | <UITableViewCellContentView: 0x199550; frame = (0 0; 276 43); layer = <CALayer: 0x18cb70>>
|    |    |    |    |    |    |    | <UIImageView: 0x18c6a0; frame = (0 0; 43 43); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x189a90>>
|    |    |    |    |    |    |    | <UILabel: 0x198fe0; frame = (53 0; 213 43); text = ' '; clipsToBounds = YES; layer = <CALayer: 0x197960>>
|    |    |    |    |    |    | <UIView: 0xdeddcb0; frame = (0 43; 276 1); autoresize = W+TM; layer = <CALayer: 0xdedf720>>
|    |    |    |    |    | <UITableViewCell: 0xde73230; frame = (0 44; 276 44); text = ' '; autoresize = W; layer = <CALayer: 0xdeb92e0>>
|    |    |    |    |    |    | <UITableViewCellContentView: 0xdedc070; frame = (0 0; 276 43); layer = <CALayer: 0xdedc560>>
|    |    |    |    |    |    |    | <UIImageView: 0xdedd7e0; frame = (0 0; 43 43); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0xdedda50>>
|    |    |    |    |    |    |    | <UILabel: 0xdeddaa0; frame = (53 0; 213 43); text = ' '; clipsToBounds = YES; layer = <CALayer: 0xde9fc80>>
|    |    |    |    |    |    | <UIView: 0xdeddd60; frame = (0 43; 276 1); autoresize = W+TM; layer = <CALayer: 0xdee02c0>>
|    |    |    |    |    | <UITableViewCell: 0x1a03e0; frame = (0 0; 276 44); text = ' '; autoresize = W; layer = <CALayer: 0x190eb0>>
|    |    |    |    |    |    | <UITableViewCellContentView: 0x197a40; frame = (0 0; 276 43); layer = <CALayer: 0x197ac0>>
|    |    |    |    |    |    |    | <UIImageView: 0x19f440; frame = (0 0; 43 43); clipsToBounds = YES; opaque = NO; layer = <CALayer: 0x185c30>>
|    |    |    |    |    |    |    | <UILabel: 0xdeda920; frame = (53 0; 213 43); text = ' '; clipsToBounds = YES; layer = <CALayer: 0xdeb8d80>>
|    |    |    |    |    |    | <UIView: 0xdedb8b0; frame = (0 43; 276 1); autoresize = W+TM; layer = <CALayer: 0xded9de0>>
|    |    |    |    |    | <UIImageView: 0xdede5d0; frame = (271 287; 5 7); alpha = 0; opaque = NO; autoresize = LM; userInteractionEnabled = NO; layer = <CALayer: 0xdedd530>>
|    | <UINavigationBar: 0xde9bab0; frame = (0 20; 1024 44); clipsToBounds = YES; opaque = NO; autoresize = W; layer = <CALayer: 0xde9bbe0>>
|    |    | <UINavigationBarBackground: 0xde9d750; frame = (0 0; 1024 44); opaque = NO; autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0xde9d7e0>>
|    |    | <UINavigationItemView: 0x186830; frame = (512 21; 0 0); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x18c3a0>>
|    |    | <UINavigationItemButtonView: 0x190cf0; frame = (7 7; 104 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x196840>>
4

1 回答 1

2

从 lldb 调试器输出:alpha您的UITableView为 0。

<UITableView: 0xe97d800; frame = (226 164; 276 338); clipsToBounds = YES; alpha = 0; opaque = NO; autoresize = W+H; layer = <CALayer: 0xdede2c0>; contentOffset: {0, 0}>

于 2012-12-14T21:13:32.233 回答