小编Mor*_*Man的帖子

在取消分配时尝试加载视图控制器的视图... UISearchController

我有创建UISearchController' in my UIVIew'sviewDidLoad`的代码.

 self.resultSearchController = ({
        let controller = UISearchController(searchResultsController: nil)
        controller.searchResultsUpdater = self
        controller.searchBar.delegate = self
        controller.dimsBackgroundDuringPresentation = false
        controller.searchBar.sizeToFit()
        controller.hidesNavigationBarDuringPresentation = false //prevent search bar from moving
        controller.searchBar.placeholder = "Search for song"

        self.myTableView.tableHeaderView = controller.searchBar

        return controller

    })()
Run Code Online (Sandbox Code Playgroud)

在此关闭完成后,此警告将出现在控制台中:

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UISearchController: 0x154d39700>)
Run Code Online (Sandbox Code Playgroud)

我不知道我做错了什么.这个类似的问题并不是我的情况(至少我不这么认为).到底是怎么回事?

ios swift uisearchcontroller

79
推荐指数
7
解决办法
3万
查看次数

警告:尝试在<...>上呈现<UIAlertController:0x7facd3946920>已经呈现(null)

我有一个长按手势一组UITableView呈现一个UIAlertController包含单元格的文本.当UIAlertController提出时,我得到这个警告:

Attempt to present <UIAlertController: 0x7fd57384e8e0>  on <TaskAppV2.MainTaskView: 0x7fd571701150> which is already presenting (null)
Run Code Online (Sandbox Code Playgroud)

根据我的理解,MainTaskView(UITableView)已经呈现了一个视图,因此它不应该呈现第二个视图,UIAlertController.所以我从类似的问题尝试了这个解决方案.它不起作用,因为我收到相同的警告.我该怎么做才能解决这个警告?请参阅下面的代码:

func longPressedView(gestureRecognizer: UIGestureRecognizer){

    /*Get cell info from where user tapped*/
    if (gestureRecognizer.state == UIGestureRecognizerState.Ended) {
        var tapLocation: CGPoint = gestureRecognizer.locationInView(self.tableView)

        var tappedIndexPath: NSIndexPath? = self.tableView.indexPathForRowAtPoint(tapLocation)
        if (tappedIndexPath != nil) {
            var tappedCell: UITableViewCell? = self.tableView.cellForRowAtIndexPath(tappedIndexPath!)
            println("the cell task name is \(tappedCell!.textLabel!.text!)")
        } else {
            println("You didn't tap on a cell")
        }
    }

    /*Long …
Run Code Online (Sandbox Code Playgroud)

uitableview ios swift uialertcontroller

21
推荐指数
2
解决办法
1万
查看次数

将未知的ArrayList类型传递给方法

假设我有这两个ArrayLists:

ArrayList<Book> book = new ArrayList<>();
ArrayList<Journal> journal = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

Book并且Journal是两个不同的类.

两者BookJournal对象都有一个getYear()方法.我想创建一个传入未知ArrayList类型的方法,并将传入的年份与列表中的对象进行比较.以下代码为main:

public static void fooBar(int year, ArrayList<?> list)
{
    if(list.get(0).getYear() == year) // does not work!
    {
    }
}
Run Code Online (Sandbox Code Playgroud)

如果将未知类型传递给方法,则无法使用该对象的方法(getYear()).如果不做两个做同样事情的方法(一个用于Book一个用于一个Journal),我怎么能这样做呢?

java arraylist

8
推荐指数
1
解决办法
1751
查看次数

在 OS X 上卸载 Valgrind

我想从我的系统中完全删除 valgrind。我删除了用brew安装valgrind时创建的valgrind-trunk文件夹。当我运行 valgrind 时,我得到

valgrind: Unknown/uninstalled VG_PLATFORM 'amd64-darwin'
Run Code Online (Sandbox Code Playgroud)

当我跑步时brew uninstall valgrind,我得到

Error: No such keg: /usr/local/Cellar/valgrind
Run Code Online (Sandbox Code Playgroud)

我在酋长岩。如何从我的系统中删除 valgrind?

valgrind osx-elcapitan

5
推荐指数
0
解决办法
2485
查看次数

了解 tkinter Treeview

我正在尝试创建一个 Treeview - 这是我的代码:

def treeview(self):
        tree = Treeview(self.parent, columns=("no","name","props","subs", "summary"))

        tree.heading('#0', text='No.')
        tree.column('#0', width=100)
        tree.heading('#1', text='Name')
        tree.column('#1', width=100)
        tree.heading('#2', text='Props')
        tree.column('#2', width=100)
        tree.heading('#3', text='Subs')
        tree.column('#3', width=100)
        tree.heading('#4', text='Summary')
        tree.column('#4', width=100)

        tree.place(relx=0.5,rely=0.2, anchor=CENTER)
Run Code Online (Sandbox Code Playgroud)

应该有 5 列 - 但是,最后一列右侧有第六个空白列。为什么是这样?

另外,我如何实际向每一列添加文本?谢谢!

tkinter python-3.x

5
推荐指数
1
解决办法
2651
查看次数

Valgrind报告了太多的mallocs

考虑以下代码:

int main(int argc, char const *argv[])
{
    char *string = NULL;
    string = malloc(sizeof(char) * 30);
    free(string);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我malloc一个char指针然后我释放它.现在考虑valgrind输出:

==58317== Memcheck, a memory error detector
==58317== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==58317== Using Valgrind-3.11.0.SVN and LibVEX; rerun with -h for copyright info
==58317== Command: ./a.out
==58317== 
==58317== 
==58317== HEAP SUMMARY:
==58317==     in use at exit: 34,941 bytes in 424 blocks
==58317==   total heap usage: 505 allocs, 81 frees, 41,099 bytes allocated …
Run Code Online (Sandbox Code Playgroud)

c malloc free valgrind

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

在Swift 2中设置animateWithDuration中的选项

我使用以下代码为文本字段设置动画:

UIView.animateWithDuration(0.5, delay: 0.4,
        options: .Repeat | .Autoreverse | .CurveEaseOut, animations: {
            self.password.center.x += self.view.bounds.width
        }, completion: nil)
Run Code Online (Sandbox Code Playgroud)

我收到了错误 Could not find member 'Repeat'

只有在我只设置一个选项时,代码才有效.为什么不让我设置多个选项?

uiview animatewithduration swift2

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

完成用户在屏幕外点击UISearchBar的动画

轻触a时UISearchBar,取消按钮滑入,TextField位于上方以容纳按钮.我将这称为取消按钮动画.

在我的应用程序中,当用户点击搜索按钮时,带有a UISearchControllerUITableView淡入的视图.我希望​​视图淡入,取消按钮动画已经完成.与iOS音乐应用类似.我试过这个:

self.myTableView.frame = CGRectMake(0, 20, self.view.bounds.width, self.view.bounds.height - 20)
self.resultSearchController.searchBar.becomeFirstResponder()

UIView.animateWithDuration(0.3, delay: 0.0, options: .CurveLinear, animations: {
    self.myTableView.alpha = CGFloat(1.0)

        }, completion: nil)
Run Code Online (Sandbox Code Playgroud)

当我将searchBar第一响应者关闭屏幕时,不应该完成取消按钮动画完成吗?它没有.

现在,取消按钮动画在屏幕上发生,然后视图(TableView)淡入.如何在视图的alpha为0时进行取消按钮动画?

animation uitableview ios swift uisearchcontroller

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

while(foo)vs while(foo!= NULL)

有人可以解释while(foo)vs while(foo != NULL)是如何相同的?也:

while(!foo) VS while(foo == NULL)

我知道 !不是,但这就是我所知道的.

c while-loop

3
推荐指数
1
解决办法
8331
查看次数

向 UIViewController 添加“编辑”按钮

我熟悉这段代码:self.navigationItem.leftBarButtonItem = self.editButtonItem

看这段代码:

class ThirdViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

@IBOutlet var tblTasks: UITableView! // declaring this allows you to reload the tableView to update your items

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.rightBarButtonItem = self.editButtonItem()
}
Run Code Online (Sandbox Code Playgroud)

我有允许存在编辑按钮的代码,但在我的应用程序和情节提要中都看不到编辑按钮。

我是 Swift 初学者,如果有人能指出我正确的方向,那就太好了。

ios swift

3
推荐指数
1
解决办法
2161
查看次数