- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在一个应用程序中有 2 个 Controller ,因为我正在尝试这些不同的设置。
一个是 UITableViewController,据我所知,它的委托(delegate)和数据源是从父类(super class)中提取的。
现在按照这个理论,我现在也有一个带有 UITableView 的 UIViewController,并且在头文件中我已经声明了数据源和委托(delegate)。
到目前为止一切顺利:-)
现在这是我不明白的一点:
在实现文件中,我可以使用 tableView 指针链接数据,但我使用的是 Core Data,并且我有这段代码:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView beginUpdates];
}
如果我不设置一个 UIViewController,这种情况和其他 5 种情况都会出错
IBOutlet UITableView *tableView;
当然是合成了:-)
但是如果我声明这个 tableView,我会在这样的行上收到一个双倍警告:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
因为它还声明了一个tableView。
所以我有两个问题:
1) 如果我已经设置了 UITableViewDatasource 和 Delegate,为什么还必须设置 IBOutlet?
2) 如果我给 UITableViewCell 一个不同的指针名称——比如 tableView2,为什么我在编辑数据时看不到变化,而只能在重新启动应用程序后看到结果?
MasterViewController,也就是UITableViewController没有这个选项。
干杯杰夫
---添加图像----
为了进入编辑模式,我在 viewDidLoad 中有这段代码
self.navigationItem.leftBarButtonItem = self.editButtonItem;
然后我使用此代码来执行需要完成的操作:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{ 如果(editingStyle == UITableViewCellEditingStyleDelete){ NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
NSError *error = nil;
if (![context save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
现在 + 选项有效,但我只有在重新启动应用程序后才能看到结果。我可以滑动和删除,但它不会在应用程序的同一实例中实时动画。
最佳答案
您已经声明了一个名为 tableView 的属性,并且可能只是用相同的名称合成了它。
UITableViewController
也有一个名为 tableView 的属性,但是 backing ivar 将被称为不同的东西,可能是 _tableView
,正是因为默认的 tableview 数据源和委托(delegate)方法通常传入一个名为 tableView
的参数,在方法的范围内,它与您的实例变量发生冲突。
在该方法中,tableView
是什么意思?传入的参数,还是你的 ivar?
回答您的具体问题:
当您的 View Controller 需要与 TableView 对话时(例如当您告诉它开始更新时),您需要这些实例的导出。当 TableView 需要与您的 View Controller 通信时(比如当它请求一个单元格时),数据源和委托(delegate)连接就在那里。
我不确定您在这里问的是什么,您可以随意调用 TableView 的导出,但您还必须更改向 self.tableView
发送消息的所有内容。为了一致性,我会像这样合成属性:
@synthesize tableView = _tableview;
这首先阻止了名为 tableView
的 ivar 存在。我假设您还没有声明 ivar,并且只将该属性声明为 IBOutlet?:
@property (nonatomic) IBOutlet UITableView *tableView;
关于ios - UITableViewController 与 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10188179/
我正在使用 Swift 制作一个应用程序,但遇到了一个问题:我有一个系统,人们可以在其中发布“帖子”,并对这些“帖子”发表评论。 为了显示这一点,我有一个 UITableViewController
用户点击“远程”按钮,然后加载以下 UITableViewController: 然后用户选择我调用的任何值: [self.navigationController popViewController
在我离开页面并使用 UITabBarController 返回后,我的 TableViewController 在页面顶部留下了一个空隙。在初始加载时它很好,只有当我离开页面然后返回时才会出现间隙。我
我有一个 TableViewController (VC1) 设置为推送到另一个 TableViewController (VC2)。这个连接是通过从 VC1 到 VC2 的 ctrl-drag 在
在我的核心数据模型中,我有一个 Person 实体,它与 Course 实体具有“对多”关系(我还具有从 Course 到 Person 的反向“对一”关系)。 现在我有一个子类化的 UITableV
为什么不调用 numberOfSectionsInTableView 方法?如果我在 viewDidLoad 中添加 [self.tableView reloadData],它就会被调用,但即便如此,
在 UITableViewController 中,我有一个方法可以更新显示总价的底部工具栏。 public override UITableViewCell GetCell(UITa
我正在制作一个 iPad 应用程序,其中包含一个用于设置选项的 View 。这个“选项” View 有两个容器 View ,每个容器 View 都包含一个 TableView,其中包含两种不同的选项,
假设设置是 导航 Controller -> GradLevelUITableViewController -> DegreeUITableViewController -> View Control
我的问题是,这是否可能,如果可能,您将如何完成这项任务? 有人知道已经在使用此功能的应用程序,或者可以从哪里获得一些示例代码吗? 此外,如果我要在对主题了解不多的情况下自行实现此操作,您估计需要多长时
当 UITableViewController 的框架低于特定高度时,UITableViewController refreshControl 会出现问题。 就目前而言,我有一个 UIViewCont
我有我的主视图和一个 RoutinesTableViewController。 我想放松回到我的 VC 并尝试了这个: @IBAction func selectRoutine(segue:UISto
我是 swift 和 Xcode 的新手,我正在尝试一些事情。当我转到设置页面时,我想在设置页面(在应用程序中,而不是在设置 bundle 中)设置开关状态。 (我将segue设置为push)为此,我
我目前正在尝试将不同的实体从我的 CoreData 模型加载到一个 UITableView 中,但位于不同的部分下。我尝试过以下方法: override func tableView(tableVie
我试图让 tableview 适应 Swift 中键盘的显示。根据文档,如果 tableview 是 UITableViewController 的子类,它应该自动调整。已经在这里阅读了很多答案,只是
我想捕获UITableViewController中触摸点的x位置。网上描述的最简单的解决方案是UITapGestureRecognizer:enter link description here 但
我是 iPhone 编程的初学者。我的第一个应用程序是 UITableViewController 但现在我想尝试一下。这个想法是创建一个如下所示的自定义布局: 布局: ---------------
我有一个基于导航的应用程序,我将 UITableViewControllers 推送到堆栈上。我想向我的所有 UITableViewControllers 添加背景 UImage。不是 UIColor
在找到位置后,我尝试在 UITableViewController 中重新加载数据。这也意味着在 viewDidLoad 方法之后。我的类正在使用此接口(interface)扩展 UITableVie
我有一个TabBarController,其中一个选项卡包含一个 subview ,它是一个navigationController。然后,我将继承 UITableViewController 形式的
我是一名优秀的程序员,十分优秀!