自定义空TableView

发布于 2024-10-01 01:47:06 字数 215 浏览 0 评论 0原文

嘿伙计们, 我遇到一个有趣的问题,我想要一个带有圆角和特定背景等的自定义表格视图...这工作正常,但一切都在 cellForRowAtIndexPath 中设置。这意味着如果我的表视图为空,则不会调用此方法,并且会显示这个丑陋的空白表视图。

我无法在 viewDidAppear 中进行修改,因为 tableView 是在其方法中声明的,例如前面提到的方法。有什么想法吗?

提前致谢!

Hey guys,
I'm having an interesting issue, where I want to have a customized table view with rounded corners and a specific background, etc... This works fine, but everything is being set up in cellForRowAtIndexPath. This means that if my table view is empty, this method doesn't get called, and I get this ugly, blank table view showing up.

I can't do the modifications in viewDidAppear, because the tableView gets declared in its methods such as the one mentioned earlier. Any ideas?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仅此而已 2024-10-08 01:47:06

听起来您只需要找到正确的位置来初始化表视图,并且由于您提到的原因,它不在 cellForRowAtIndexPath 中。假设您已在 xib 文件中创建了 UITableView,则可以在源代码中创建一个插座(见下文),并在 InterfaceBuilder 中在 xib 文件中创建控制器的实例,或使用现有实例(如 File's Owner) , 或许)。在 IB 中,通过按住 Control 键单击并拖动将该插座连接到表。当 xib 被加载时,UIKit 将填充指向你的表视图的指针,然后你可以在 viewDidLoad 期间疯狂地使用它。这能解决你的问题吗?

@interface MyController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * myTable;
}
@property (nonatomic,assign) IBOutlet UITableView * myTableView;
@end

...

@implementation MyController
@synthesize myTableView;
-(void)viewDidLoad
{
    // do some crazy initialization with self.myTableView!
}
@end

Sounds like you just need to find the right spot to initialize your table view, and it's not in cellForRowAtIndexPath, for the reasons you mentioned. Assuming you've created your UITableView in a xib file, you can create an outlet in your source code (see below), and in InterfaceBuilder either make an instance of your controller in the xib file, or use an existing instance (like File's Owner, maybe). In IB, connect that outlet to the table with control-click-drag. When the xib is loaded, UIKit will fill in the pointer to your table view, which you can then go nuts with during viewDidLoad. Does that solve your problem?

@interface MyController : UIViewController<UITableViewDelegate,UITableViewDataSource>
{
    UITableView * myTable;
}
@property (nonatomic,assign) IBOutlet UITableView * myTableView;
@end

...

@implementation MyController
@synthesize myTableView;
-(void)viewDidLoad
{
    // do some crazy initialization with self.myTableView!
}
@end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文