男装,
我需要一些帮助.这几乎就像我知道我正在尝试做什么,但在编码时我一直无法使它工作.场景是我有一个视图控制器,其中包含一个表视图.我的表视图有三种不同的动态原型,因为我有三种不同的单元格.现在,我想要做的就是指定在哪一行中生成哪个原型单元格.我还在故事板中给出了每个原型单元的唯一标识符.
我理解的方法是我的cellforRowatIndexpath方法需要了解在该行中显示哪种类型的单元格,然后选择标识符,出列并根据需要设置内容.
相应地,这是我的代码,我正在尝试做的事情:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath * )indexPath
{
if(indexPath.row==0)
{
static NSString *CellIdentifier = @"HelloCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// configure your cell here...
return cell;
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,事情没有按计划运行,我的应用程序崩溃给了我一个2013-02-07 16:47:39.859 ProjectsABC30068:c07] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [NSIndexPath setTableViewStyle:] :无法识别的选择器发送到实例0x83812e0'错误.
由于我已正确设置数据源和委托,因此表视图没有问题.并且还为表格视图制作了一个出口.
我还尝试将cellforRowAtIndexPath中的if语句更改为if(myTable.indexPathForSelectedRow == 0).这会在所有单元格中生成动态原型,但至少应用程序不会停止.
你们认为这是什么问题?
我不知道如何正确使用索引路径,如果有人可以帮助我,我会很感激.
我有一个登录视图,检查是否有默认设置,然后同步数据.如果没有默认设置,则视图等待用户登录.如果有设置和数据同步正确,它应切换到我的拆分视图.
如果用户输入其登录信息,则代码有效.它同步数据,然后切换视图.如果用户已登录,则会触发该功能并且不会切换视图.
以下是两个路径调用的代码:
-(void)redirect{
NSLog(@"Redirect@");
UISplitViewController *split = [self.storyboard instantiateViewControllerWithIdentifier:@"orders_split"];
[self.view.window setRootViewController:split];
}
Run Code Online (Sandbox Code Playgroud)
如果用户已登录一次,"Redirect @"会在初始加载的日志中显示.我已经确认没有同步错误,它会触发该功能但不执行切换.
我正在从带有导航控制器的标准视图移动到splitview,所以我不能使用手动segue触发器.
我有一个模型类和两个tableView控制器.此类为Integer值.这个类的值用prepareforsegue方法发送给其他类.但我无法准备forsegue获取tableView indexpath.我做错了?
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let subCategory: SubCategoryVC = segue.destinationViewController as SubCategoryVC
let indexPath = self.categoryTableView.indexPathForSelectedRow()
model = arrList[indexPath?.row] **//incorrect line**
subCategory.getCatID = model.categoryID
}
Run Code Online (Sandbox Code Playgroud) 我想在下一个ViewController上显示didSelectRowAtIndexPath并发生如下.
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var section = indexPath.section
var row = indexPath.row
var cell:UITableViewCell = self.tblView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell
cell.textLabel?.text = "hello"
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
frequentVC = storyboard.instantiateViewControllerWithIdentifier("frequentVC") as? DropOffFrequentVC
self.presentViewController(frequentVC!, animated: true,completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
该nextViewController提出和我解雇UIViewController的 self.dismissViewControllerAnimated(true, completion:nil),并再次先前UIViewController被调用,但现在,当我等待了一段时间,然后再试一次展示UIViewController中,UIViewController被称为非常缓慢,但didSelectRowAtIndexPath立即被调用.在等待期间,如果我点击查看任何地方,然后立即UIViewController呈现.此外,如果我tappapp两次UIViewController立即呈现.
instantiateViewControllerWithIdentifier和initWithNibName之间有什么区别,除了前者是故事板而后来不是?
UIStoryboard *signupStory = [UIStoryboard storyboardWithName:@"SignupStory" bundle:[NSBundle mainBundle]];
SignupLoginViewController *signUpVC = [signupStory instantiateViewControllerWithIdentifier:@"SignupVC"];
Run Code Online (Sandbox Code Playgroud)
和
SignupLoginViewController *signUpVC = [[SignupLoginViewController alloc] initWithNibName:@"SignupLoginViewController" bundle:[NSBundle mainBundle]];
Run Code Online (Sandbox Code Playgroud) 我想UITableView用这样的水平空间创建:
所以我在这里找到了解决方案
但似乎它不起作用'setFrame'功能不适用于iOS9,所以我发现另一个建议使用 layoutSubviews
override func layoutSubviews() {
super.layoutSubviews()
self.contentView.frame = UIEdgeInsetsInsetRect(self.bounds, UIEdgeInsetsMake(0, 10, 0, 10))
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用这里是我得到的:
因此,如何正确添加水平空间,我使用Swift 2,Xcode7,Storyboard自定义UITableViewCell
假设我有一个按钮,当点击时,应执行两个操作:
func firstFunction() {
...
}
func secondFunction() {
...
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以将一个对象连接到一个动作.虽然我似乎不能将它连接到多个.我试着拖放加号圈(请看图片),但它似乎没有连接到secondFunction().
功能不应该有副作用.比方说,我想firstFunction从我的代码中的某个地方打电话,但不是secondFunction.
我可以IBAction在iOS中将对象连接到更多s吗?
我遇到了一个问题,我的主要故事板在我乱搞之后被破坏了,我得到了以下神秘的错误消息.该应用程序捕获错误,main()然后SIGABRT出现以下异常:
Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '{objective 0x147dc56e0: <1:-25.3333> + <1:1>*0x147dc39b0.posErrorMarker{id: 91} +
<1:0.125>*0x147dc50e0.negError{id: 90} +
<1:-0.125>*0x147e2e300.marker{id: 77} +
<1:0.125>*0x147e2e300.slack{id: 78} +
<1:0.125>*0x147e2e350.marker{id: 81} +
<1:-1>*0x147e2e440.marker{id: 87} +
<1:-0.125>*0x147e436b0.marker{id: 63} +
<1:0.125>*0x147e437f0.marker{id: 72} +
<1:-0.125>*0x147e764c0.marker{id: 55} +
<1:0.125>*0x147e88820.marker{id: 52}}:
internal error. Setting empty vector for variable 0x147dc1b90.negError{id: 48}.'
Run Code Online (Sandbox Code Playgroud)
将另一个故事板设置为主界面可以正确启动应用程序.
如何找到导致"为变量设置空向量"故事板异常的元素?
我有一个UISearchController具有自己的自定义结果控制器的工具,而不是在即时视图中过滤内容。
在UISearchBar导航栏中正确显示,但是当我开始键入字符的搜索框中,我的自定义控制器出现,填补了整个屏幕,覆盖了导航栏,我输入我的查询到窗口。
这曾经奏效,但最近我将情节提要更改为使用情节提要UINavigationController,进入UITabBarController,然后使用选项卡式控制器。
在UITabBarController目前拥有的搜索逻辑,因此它可以通过路线我已经实现了一个协议,在搜索结果采取相应的选项卡的行为。
请注意,下面是我的故事板,自定义搜索结果控制器是位于下方的UITabBarController项目,而右上角的未附加项目则通过库使用,并在内部连接到顶部标签的控制器。
我开始怀疑这种特定的配置是否有效?我可以UINavigationController在前面UITabBarController吗?
我想要一个持久的搜索栏放在顶部,所有共享的搜索代码都放在一个位置(UITabBarController),而不是将UINavigationController放在每个选项卡的前面?
如果这可行,是否有任何想法为什么自定义搜索结果控制器现在覆盖整个屏幕,而不是进入导航栏?
我有一个UIView是@IBDesignable
@IBDesignable
class MyView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
sharedInit()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
sharedInit()
}
private func sharedInit(){
translatesAutoresizingMaskIntoConstraints = false
backgroundColor = .blue
}
}
Run Code Online (Sandbox Code Playgroud)
当我将其放置UIView在情节提要中并MyView在“ 身份”检查器中将其类分配给时,UIView仍然具有默认的背景色。为什么其背景颜色不在UIColor.blue情节提要中?而且,请问我该怎么做呢?
谢谢你的帮助。
uistoryboard ×10
ios ×9
uitableview ×4
objective-c ×3
swift ×3
exception ×1
ibaction ×1
ibdesignable ×1
ios9 ×1
nsindexpath ×1
rootview ×1
swift2 ×1
swift3 ×1
xib ×1