iphone - 代码驱动的 UITableView 不委托(delegate)

标签 iphone objective-c cocoa-touch ios uitableview

我有一个通过 initWithFrame 动态添加的 UITableView。

- (void)twitterUpdate {
twitterTable = [[UITableView alloc] initWithFrame:CGRectMake(40, 100, 420, 750)];
twitterTable.delegate = self;
twitterTable.backgroundColor = [UIColor clearColor];
twitterTable.separatorColor = [UIColor darkGrayColor];
twitterTable.dataSource = self;
[twitterView addSubview:twitterTable];
}

不幸的是,

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

虽然我有但没有被调用

<UITableViewDataSource, UITableViewDelegate>

在我的标题中定义。

关于为什么不调用它的任何想法?正在通过

调用 twitterUpdate
[self performSelectorOnMainThread:@selector(twitterUpdate) withObject:self waitUntilDone:YES];

并且正在将表格绘制到页面上。我也有

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 

返回一个有效的 NSInteger。

你不能像这样动态创建表吗?

最佳答案

确保你打电话:

[twitterTable reloadData];

关于iphone - 代码驱动的 UITableView 不委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5381774/

相关文章:

objective-c - 将 (void *) 转换为 (SInt16 *) 到 Swift

ios - 是否可以从共享扩展执行 API 调用

iphone - 为什么我的 x 轴在 iPhone 上不显示核心图?

iphone - 从 Facebook API iOS 的另一个 View Controller 调用方法

iphone - 如何创建高分辨率的 iPhone 启动图像?

iphone - 每次点击 4 个按钮标题更改

iphone - 无法将对象添加到返回 nil 的可变数组

ios - 是否有一种行之有效的系统方法来了解在使用类(class)时我应该包括哪些内容

cocoa-touch - 临时构建更改文档目录

cocoa /iPhone : BackgroundColor and Opaque Properties