【问题标题】:UITableView in an UIScrollViewUIScrollView 中的 UITableView
【发布时间】:2023-03-25 04:29:01
【问题描述】:

我这里有问题。所以我要做的是在分页的 UIScrollView 中添加几个 TableView。我有一个名为 CustomView 的类,它是 UITableView 类。它可以作为表格视图单独工作。所以它没有问题。所以我尝试在 .h 文件中像这样添加它们:

#import <UIKit/UIKit.h>

    @interface PagedScrollViewController : UIViewController {

    UIScrollView *scrollView;

}

@property (nonatomic, retain) IBOutlet UIScrollView *scrollView;

@end

在 .m 中:

    @synthesize scrollView;

        - (void)viewDidLoad
        {
            [super viewDidLoad];
            int numberOfPages = 3;
            for (int i = 0; i < numberOfPages; i++) {
                CGRect frame = CGRectMake(self.scrollView.frame.size.width * i,
                                      0.0,
                                      self.scrollView.frame.size.width,
                                      self.scrollView.frame.size.height);
            CustomView *customView = [[CustomView alloc] initWithStyle:UITableViewStyleGrouped];
            customView.view.frame = frame;
            [self.scrollView addSubview:customView.view];
        }

        self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * numberOfPages,
                                                 self.scrollView.frame.size.height - self.navigationController.navigationBar.frame.size.height);

    }

它只显示一个没有任何单元格的空表视图。我究竟做错了什么?顺便说一句,在我开始使用故事板之前,它工作得很好。 提前谢谢你。

更重要的是,在 iOS 5 上,我在控制台中获得了 Sigabrt: 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[CALayer numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x6a2fc00”

【问题讨论】:

    标签: ios uitableview uiscrollview


    【解决方案1】:

    试试这个

    [customView.tableView reloadData]
    

    【讨论】:

    • 我应该在周期内尝试吗?
    【解决方案2】:

    我认为如果你没有实现,你必须实现 require UITableViewDataSource 方法。

    喜欢:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    

    【讨论】:

    • 是的,我在 CustomView 类中做到了
    猜你喜欢
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多