【问题标题】:UIView and UITableViewUIView 和 UITableView
【发布时间】:2012-04-07 05:20:13
【问题描述】:

我在尝试在我的 tableView 中编写代码时遇到了问题。我会解释...我正在使用情节提要并想在我的第二个选项卡中制作一个 RSS 提要。我正在浏览 Ray W 的 RSS Feed 教程,可在此处找到 RSS Tutorial

我几乎完成了本教程的 ASIHTTPRequest 部分,并且已经到了需要编写这段代码的地步了

`- (void)requestFinished:(ASIHTTPRequest *)request {

RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:request.url.absoluteString
                                           articleTitle:request.url.absoluteString
                                             articleUrl:request.url.absoluteString
                                            articleDate:[NSDate date]] autorelease];    
int insertIdx = 0;                    
[_allEntries insertObject:entry atIndex:insertIdx];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:0]]
                      withRowAnimation:UITableViewRowAnimationRight]; 

}`

我的问题是当我输入 self.tableView 时出现错误。错误是:**在“SecondViewController”类型的对象上找不到属性“tableView”

**

SecondViewController.h 文件有@interface SecondViewController : UIViewController { 所以我认为这就是错误出现的原因。当我将@interface 部分添加到 UITableViewController 时,错误消失了,但是当我运行项目并单击 RSS Feed 选项卡时,它会崩溃并出现以下错误Terminating app due to uncaught exception 'NSInternalInconsistencyException'

有人解决这个问题吗?谢谢。

【问题讨论】:

  • 查看异常的文本。如果您使用UITableViewController 的子类,则其view 属性必须UITableView 的实例。另一方面,可以将UIViewController 的子类放入作为其主视图子视图的表视图的委托/数据源中;只需声明它符合UITableViewDelegateUITableViewDataSource 并以通常的方式实现委托方法。您不会自动获得tableView 属性,但您始终可以创建自己的UITableView 插座并自行连接。
  • @warrenm:感谢您的及时回复。对不起,但我绝对是菜鸟。你能以更简单的方式让我完成我需要做的事情吗?再次感谢。
  • 我想我已经做到了。我通过 .h 文件的 @interface 位做了 UITableViewDelegate 和 DataSource 。然后在下面,我写了 UITableViewController *tableViewController;然后在 .m 文件中,我将 self.tableView 替换为 tableViewController.tableView。对吗?
  • 没有。再看一遍,您似乎真的希望SecondViewController 成为UITableViewController 的子类,但不知何故,它被创建为UIViewController 的子类。您能否发布异常描述的确切措辞(即,当SecondViewControllerUITableViewController 但似乎没有正确设置其出口时发生的内部不一致异常)?
  • 嘿,我已经上传了输出的截图。 imgur.com/1XF9x 谢谢。

标签: iphone objective-c xcode uiviewcontroller uitableview


【解决方案1】:

请在 sendViewController 中添加 tableView 作为属性,然后设置其数据源 鉴于确实加载为:

在 SecondViewController.h 中添加

@property (weak) IBOutlet UITableView *tableView;

在 SecondViewController.h 中添加

-(void)viewDidLoad
{
    self.tableView.dataSource = self;
    .
    .
    .
    .
    .// your code here...
}

最后在你的界面构建器中将这个 tableview 与 table view 连接起来..

希望这会有所帮助.... :)

【讨论】:

    猜你喜欢
    • 2015-09-30
    • 1970-01-01
    • 1970-01-01
    • 2017-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多