小编ale*_*lex的帖子

动态更改UITableView高度

我想基于其单元格高度的总和从另一个viewcontroller更改tableview的高度,因为它们是动态的.它可能吗?谢谢

添加在:

我基本上拥有一个UserProfileViewController,它在屏幕的一半上有一个容器视图.在那里我添加了不同的其他viewcontrollers:

在此输入图像描述

在此输入图像描述

在wall按钮的情况下,这是我添加viewcontroller的方式,它是后续的tableview:

- (IBAction)wallButtonPressed:(id)sender
{
    //Check if there is an instance of the viewcontroller we want to display. If not make one and set it's tableview frame to the container's view bounds
    if(!_userWallViewController) {
        self.userWallViewController = [[WallViewController alloc] init];
//        self.userWallViewController.activityFeedTableView.frame = self.containerView.bounds;

    }

    [self.userWallViewController.containerView addSubview:self.userWallViewController.activityFeedTableView];
    //If the currentviewcontroller adn it's view are already added to the hierarchy remove them
    [self.currentViewController.view removeFromSuperview];
    [self.currentViewController removeFromParentViewController];

    //Add the desired viewcontroller to the currentviewcontroller
    self.currentViewController = self.userWallViewController;

    //Pass the data needed …
Run Code Online (Sandbox Code Playgroud)

height dynamic uitableview ios

62
推荐指数
5
解决办法
12万
查看次数

swift闭包存储和作为变量访问

我想在swift项目中实现一个回调,就像我以前在Objective-C中做的一样,我需要一个类型为closure的变量.该闭包应该作为参数作为对象并且不返回任何内容.

var downloadCompleted: (MLBook) -> (Void)!
Run Code Online (Sandbox Code Playgroud)

当我需要触发回调时,我这样做:

if self.downloadCompleted {
   self.downloadCompleted(book)
}
Run Code Online (Sandbox Code Playgroud)

编译器抱怨此错误消息:

 Type '(MLBook) -> (Void)!' does not conform to protocol 'BooleanType'
Run Code Online (Sandbox Code Playgroud)

如果删除if语句,编译器会说:

Property 'self.downloadCompleted' not initialized
Run Code Online (Sandbox Code Playgroud)

即使它被隐含地打开了.

当我尝试获得回调时:

BookStore.sharedInstance.downloadCompleted{(book: MLBook) -> () in
   println("Print if you got the callback")
}
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

'(MLBook) -> ()' is not convertible to 'MLBook'
Run Code Online (Sandbox Code Playgroud)

我更担心最后一条错误消息,因为我不太确定它要告诉我什么.

任何帮助,将不胜感激.谢谢

variables closures callback swift

4
推荐指数
2
解决办法
6073
查看次数

快速显示动态范围的循环

...或者如何在for循环条件中使用索引

大家好,因为我们在Swift 3中没有使用c风格的循环,所以我似乎找不到找到一种方式来表达更复杂的循环,因此也许您可以帮帮我。

如果我要写这个

for(int i=5; num/i > 0; i*=5)
Run Code Online (Sandbox Code Playgroud)

快速3我该怎么做?

我关闭的时间是:

for i in stride(from: 5, through: num, by: 5) where num/i > 0 
Run Code Online (Sandbox Code Playgroud)

但这当然会一次迭代5个块,如果我是:5、25、125等。

有任何想法吗?

谢谢

iteration for-loop swift swift3

4
推荐指数
1
解决办法
837
查看次数