[英]How do I tell the difference between the user tapping my table view cell and the user tapping a subview contained within the cell?
[英]How do I use the data within my query within a table view cell?
我正在制作一個基本的iOS應用程序,在該應用程序中我有一個table-view-controller。 我需要此控制器根據我的Parse.com數據庫中的信息填充單元格。
這是我特別需要的信息:
候選人圖像(這是一個圖像文件)
override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) // Retrieves the name from DB let nameQuery = PFQuery(className: "Candidate") // Network request nameQuery.findObjectsInBackgroundWithBlock { (result: [AnyObject]?, error: NSError?) -> Void in if error == nil && result != nil { // The find succeeded. println(result?.count) } else { // Log details of the failure println("Error: \\(error!) \\(error!.userInfo)") } } }
我可以按預期取回對象,但是如何僅獲取名稱和圖像呢? 我是否對每個信息都做兩個單獨的查詢?
我要事先道歉,我要用Objective-C寫下答案,因為我還沒學會快速! :-)因此,基本上在您的類中創建一個NSArray
。 假設您將其命名為數據。 在您的viewDidLoad
,只需使用:
PFQuery *query = [PFQuery queryWithClassName:@"Candidate"];
data = [query findObjects];
在您的numberOfRowsInSection
,只需將return [query countObjects];
在cellForIndexPath:(NSIndexPath *)indexPath
,可以通過執行((PFObject *)(data[indexPath.row]))[@"attr"]
來獲取對象的數據。
希望這可以幫助。
有大量關於iOS Swift + Parse的出色教程。 深入研究教程 ,您將輕松地學習如何完成工作。
回答后面的問題,只要將名稱和圖像與Candidate類相關聯,就只需一個查詢。
祝你好運,玩得開心!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.